Migrate documents to App Group

This commit is contained in:
Davide De Rosa 2019-03-10 14:58:01 +01:00
parent 8ede1ed3d4
commit 87249cb8ad
1 changed files with 23 additions and 0 deletions

View File

@ -51,6 +51,7 @@ class TransientStore {
} }
private init() { private init() {
TransientStore.migrateDocumentsToAppGroup()
// this must be graceful // this must be graceful
ConnectionService.migrateJSON(from: TransientStore.serviceURL, to: TransientStore.serviceURL) ConnectionService.migrateJSON(from: TransientStore.serviceURL, to: TransientStore.serviceURL)
@ -85,4 +86,26 @@ class TransientStore {
service.saveProfiles() 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)")
}
}
} }