Skip to content

Commit

Permalink
Don't support transferring Ruuvi Station data on device change (#1852)
Browse files Browse the repository at this point in the history
fixes #1848
  • Loading branch information
rinat-enikeev authored Jan 9, 2024
1 parent 26601ad commit df5e3ae
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
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

0 comments on commit df5e3ae

Please sign in to comment.