Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't support transferring Ruuvi Station data on device change #1852

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ private final class MigrationAssembly: Assembly {
let settings = r.resolve(RuuviLocalSettings.self)!
let idPersistence = r.resolve(RuuviLocalIDs.self)!
let ruuviPool = r.resolve(RuuviPool.self)!
let sqliteContext = r.resolve(SQLiteContext.self)!
let ruuviStorage = r.resolve(RuuviStorage.self)!
let ruuviAlertService = r.resolve(RuuviServiceAlert.self)!
let ruuviOffsetCalibrationService = r.resolve(RuuviServiceOffsetCalibration.self)!
return RuuviMigrationFactoryImpl(
settings: settings,
idPersistence: idPersistence,
ruuviPool: ruuviPool,
sqliteContext: sqliteContext,
ruuviStorage: ruuviStorage,
ruuviAlertService: ruuviAlertService,
ruuviOffsetCalibrationService: ruuviOffsetCalibrationService
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation
import RuuviContext

final class MigrationManagerIsExcludedFromBackup: RuuviMigration {
private let sqliteContext: SQLiteContext

init(sqliteContext: SQLiteContext) {
self.sqliteContext = sqliteContext
}

func migrateIfNeeded() {
let databaseUrl = NSURL(fileURLWithPath: sqliteContext.database.dbPath)
do {
let resourceValues = try databaseUrl.resourceValues(forKeys: [.isExcludedFromBackupKey])
guard resourceValues[.isExcludedFromBackupKey] == nil
|| resourceValues[.isExcludedFromBackupKey] as? Bool == false else {
return
}
try databaseUrl.setResourceValue(true, forKey: .isExcludedFromBackupKey)
} catch let error as NSError {
print("Error excluding \(databaseUrl.lastPathComponent ?? "") from backup \(error)")
}
}

private let migratedUdKey = "MigrationManagerIsExcludedFromBackup.migrated"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public final class RuuviMigrationFactoryImpl: RuuviMigrationFactory {
private let settings: RuuviLocalSettings
private let idPersistence: RuuviLocalIDs
private let ruuviPool: RuuviPool
private let sqliteContext: SQLiteContext
private let ruuviStorage: RuuviStorage
private let ruuviAlertService: RuuviServiceAlert
private let ruuviOffsetCalibrationService: RuuviServiceOffsetCalibration
Expand All @@ -16,13 +17,15 @@ public final class RuuviMigrationFactoryImpl: RuuviMigrationFactory {
settings: RuuviLocalSettings,
idPersistence: RuuviLocalIDs,
ruuviPool: RuuviPool,
sqliteContext: SQLiteContext,
ruuviStorage: RuuviStorage,
ruuviAlertService: RuuviServiceAlert,
ruuviOffsetCalibrationService: RuuviServiceOffsetCalibration
) {
self.settings = settings
self.idPersistence = idPersistence
self.ruuviPool = ruuviPool
self.sqliteContext = sqliteContext
self.ruuviStorage = ruuviStorage
self.ruuviAlertService = ruuviAlertService
self.ruuviOffsetCalibrationService = ruuviOffsetCalibrationService
Expand Down Expand Up @@ -50,6 +53,7 @@ public final class RuuviMigrationFactoryImpl: RuuviMigrationFactory {
ruuviAlertService: ruuviAlertService
)
let toNetworkPull60 = MigrationManagerToNetworkPull60(settings: settings)
let isExcludedFromBackup = MigrationManagerIsExcludedFromBackup(sqliteContext: sqliteContext)
return [
toAlertService,
toPrune240,
Expand All @@ -59,6 +63,7 @@ public final class RuuviMigrationFactoryImpl: RuuviMigrationFactory {
toTimeouts,
fixRHAlerts,
toNetworkPull60,
isExcludedFromBackup,
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class KeychainServiceImpl {
)
.label("Ruuvi Station")
.synchronizable(false)
.accessibility(.afterFirstUnlock)
.accessibility(.afterFirstUnlockThisDeviceOnly)

private enum Account: String {
case ruuviUserApi
Expand Down