Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Revert "Fix #195 Migrate database from Documents to Application Suppo…
Browse files Browse the repository at this point in the history
…rt folder (#1026)"

This reverts commit c0aa10c.
  • Loading branch information
jhreis committed Sep 17, 2019
1 parent ae8dd61 commit 592298f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 47 deletions.
1 change: 0 additions & 1 deletion Client/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions Client/Application/Migration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
42 changes: 1 addition & 41 deletions Data/models/DataController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {

Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 592298f

Please # to comment.