Migrate drafts to new file
This commit is contained in:
parent
0746e12737
commit
6b4223a9d6
|
@ -35,6 +35,17 @@ public class DraftsManager: Codable, ObservableObject {
|
|||
return DraftsManager()
|
||||
}
|
||||
|
||||
public static func migrate(from url: URL) -> Result<Void, any Error> {
|
||||
do {
|
||||
try? FileManager.default.removeItem(at: archiveURL)
|
||||
try FileManager.default.moveItem(at: url, to: archiveURL)
|
||||
} catch {
|
||||
return .failure(error)
|
||||
}
|
||||
shared = load()
|
||||
return .success(())
|
||||
}
|
||||
|
||||
private init() {}
|
||||
|
||||
public required init(from decoder: Decoder) throws {
|
||||
|
|
|
@ -11,6 +11,7 @@ import CoreData
|
|||
import OSLog
|
||||
import Sentry
|
||||
import UserAccounts
|
||||
import ComposeUI
|
||||
|
||||
let stateRestorationLogger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "StateRestoration")
|
||||
|
||||
|
@ -48,6 +49,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||
let oldDraftsFile = documentsDirectory.appendingPathComponent("drafts").appendingPathExtension("plist")
|
||||
if FileManager.default.fileExists(atPath: oldDraftsFile.path) {
|
||||
if case .failure(let error) = DraftsManager.migrate(from: oldDraftsFile) {
|
||||
SentrySDK.capture(error: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue