forked from shadowfacts/Tusker
Actually migrate to new persistent store locations
This commit is contained in:
parent
044d34d20f
commit
41775e5d19
|
@ -54,6 +54,31 @@ class MastodonCachePersistentStore: NSPersistentContainer {
|
|||
persistentStoreDescriptions = [storeDescription]
|
||||
} else {
|
||||
super.init(name: "\(accountInfo!.persistenceKey)_cache", managedObjectModel: MastodonCachePersistentStore.managedObjectModel)
|
||||
|
||||
// workaround for migrating from using id in name to persistenceKey
|
||||
// can be removed after a sufficient time has passed
|
||||
if accountInfo!.id.contains("/") {
|
||||
for desc in persistentStoreDescriptions {
|
||||
guard let new = desc.url else {
|
||||
continue
|
||||
}
|
||||
for ext in ["sqlite", "sqlite-shm", "sqlite-wal"] {
|
||||
var old = new.deletingLastPathComponent()
|
||||
let components = accountInfo!.id.split(separator: "/")
|
||||
for dir in components.dropLast(1) {
|
||||
old.appendPathComponent(String(dir), isDirectory: true)
|
||||
}
|
||||
old.appendPathComponent("\(components.last!)_cache", isDirectory: false)
|
||||
old.appendPathExtension(ext)
|
||||
if FileManager.default.fileExists(atPath: old.path) {
|
||||
var expected = new.deletingLastPathComponent()
|
||||
expected.appendPathComponent("\(accountInfo!.persistenceKey)_cache", isDirectory: false)
|
||||
expected.appendPathExtension(ext)
|
||||
try? FileManager.default.moveItem(at: old, to: expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadPersistentStores { (description, error) in
|
||||
|
|
Loading…
Reference in New Issue