forked from shadowfacts/Tusker
Further tweak persistent store migration
This commit is contained in:
parent
4be2258882
commit
bebe563e8f
|
@ -59,24 +59,27 @@ class MastodonCachePersistentStore: NSPersistentContainer {
|
||||||
// can be removed after a sufficient time has passed
|
// can be removed after a sufficient time has passed
|
||||||
if accountInfo!.id.contains("/") {
|
if accountInfo!.id.contains("/") {
|
||||||
for desc in persistentStoreDescriptions {
|
for desc in persistentStoreDescriptions {
|
||||||
guard let new = desc.url else {
|
guard let new = desc.url,
|
||||||
|
!FileManager.default.fileExists(atPath: new.path) else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for ext in ["sqlite", "sqlite-shm", "sqlite-wal"] {
|
do {
|
||||||
var old = new.deletingLastPathComponent()
|
for ext in ["sqlite", "sqlite-shm", "sqlite-wal"] {
|
||||||
let components = accountInfo!.id.split(separator: "/")
|
var old = new.deletingLastPathComponent()
|
||||||
for dir in components.dropLast(1) {
|
let components = accountInfo!.id.split(separator: "/")
|
||||||
old.appendPathComponent(String(dir), isDirectory: true)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
old.appendPathComponent("\(components.last!)_cache", isDirectory: false)
|
} catch {}
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue