diff --git a/Passepartout/Sources/Model/TransientStore.swift b/Passepartout/Sources/Model/TransientStore.swift index 8a512ec8..2b64a25c 100644 --- a/Passepartout/Sources/Model/TransientStore.swift +++ b/Passepartout/Sources/Model/TransientStore.swift @@ -51,6 +51,7 @@ class TransientStore { } private init() { + TransientStore.migrateDocumentsToAppGroup() // this must be graceful ConnectionService.migrateJSON(from: TransientStore.serviceURL, to: TransientStore.serviceURL) @@ -85,4 +86,26 @@ class TransientStore { service.saveProfiles() } } + + // + + private static func migrateDocumentsToAppGroup() { + let oldDocumentsURL = FileManager.default.userURL(for: .documentDirectory, appending: nil) + let newDocumentsURL = GroupConstants.App.documentsURL + log.debug("App documentsURL: \(oldDocumentsURL)") + log.debug("Group documentsURL: \(newDocumentsURL)") + let fm = FileManager.default + do { + for c in try fm.contentsOfDirectory(atPath: oldDocumentsURL.path) { + let old = oldDocumentsURL.appendingPathComponent(c) + let new = newDocumentsURL.appendingPathComponent(c) + log.verbose("Move:") + log.verbose("\tFROM: \(old)") + log.verbose("\tTO: \(new)") + try fm.moveItem(at: old, to: new) + } + } catch let e { + log.error("Could not migrate documents to App Group: \(e)") + } + } }