diff --git a/Client/Application/AppDelegate.swift b/Client/Application/AppDelegate.swift index a5d76c309de..f938b9fc732 100644 --- a/Client/Application/AppDelegate.swift +++ b/Client/Application/AppDelegate.swift @@ -66,7 +66,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati updateShortcutItems(application) - Migration.moveDatabaseToApplicationDirectory() // Passcode checking, must happen on immediate launch if !DataController.shared.storeExists() { // Since passcode is stored in keychain it persists between installations. diff --git a/Client/Application/Migration.swift b/Client/Application/Migration.swift index faef2c2b577..9592c99ba71 100644 --- a/Client/Application/Migration.swift +++ b/Client/Application/Migration.swift @@ -25,11 +25,6 @@ class Migration { } } - static func moveDatabaseToApplicationDirectory() { - //Moves Coredata sqlite file from Documents dir to application support dir. - DataController.shared.migrateToNewPathIfNeeded() - } - /// Adblock files don't have to be moved, they now have a new directory and will be downloaded there. /// Downloads folder was nefer used before, it's a leftover from FF. private static func documentsDirectoryCleanup() { diff --git a/Data/models/DataController.swift b/Data/models/DataController.swift index e560ab31dd1..f6a377b95e2 100644 --- a/Data/models/DataController.swift +++ b/Data/models/DataController.swift @@ -30,24 +30,6 @@ public class DataController: NSObject { return FileManager.default.fileExists(atPath: storeURL.path) } - public func migrateToNewPathIfNeeded() { - func sqliteFiles(from url: URL, dbName: String) throws -> [URL] { - return try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: []).filter({$0.lastPathComponent.hasPrefix(dbName)}) - } - if FileManager.default.fileExists(atPath: oldStoreURL.path) && !storeExists() { - do { - try migrationContainer.persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: oldStoreURL, options: nil) - if let oldStore = migrationContainer.persistentStoreCoordinator.persistentStore(for: oldStoreURL) { - try migrationContainer.persistentStoreCoordinator.migratePersistentStore(oldStore, to: storeURL, options: nil, withType: NSSQLiteStoreType) - try migrationContainer.persistentStoreCoordinator.destroyPersistentStore(at: oldStoreURL, ofType: NSSQLiteStoreType, options: nil) - try sqliteFiles(from: oldStoreURL.deletingLastPathComponent(), dbName: DataController.databaseName).forEach(FileManager.default.removeItem) - } - } catch { - log.error(error) - } - } - } - // MARK: - Data framework interface static func perform(context: WriteContext = .new(inMemory: false), save: Bool = true, @@ -124,17 +106,6 @@ public class DataController: NSObject { } // MARK: - Private - private lazy var migrationContainer: NSPersistentContainer = { - - let modelName = "Model" - guard let modelURL = Bundle(for: DataController.self).url(forResource: modelName, withExtension: "momd") else { - fatalError("Error loading model from bundle") - } - guard let mom = NSManagedObjectModel(contentsOf: modelURL) else { - fatalError("Error initializing managed object model from: \(modelURL)") - } - return NSPersistentContainer(name: modelName, managedObjectModel: mom) - }() private lazy var container: NSPersistentContainer = { @@ -167,8 +138,7 @@ public class DataController: NSObject { return queue }() - /// Warning! Please use storeURL. oldStoreURL is for migration purpose only. - private let oldStoreURL: URL = { + private let storeURL: URL = { let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) guard let docURL = urls.last else { log.error("Could not load url at document directory") @@ -178,16 +148,6 @@ public class DataController: NSObject { return docURL.appendingPathComponent(DataController.databaseName) }() - private let storeURL: URL = { - let urls = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask) - guard let docURL = urls.last else { - log.error("Could not load url at application support directory") - fatalError() - } - - return docURL.appendingPathComponent(DataController.databaseName) - }() - private static func newBackgroundContext() -> NSManagedObjectContext { let backgroundContext = DataController.shared.container.newBackgroundContext() // In theory, the merge policy should not matter