From 51961dd737e709c3f274608b3cf89376b2df0d47 Mon Sep 17 00:00:00 2001 From: Zheng-Xiang Ke Date: Sat, 6 Jan 2018 10:22:44 +0800 Subject: [PATCH] Migrate external storage --- Sources/DataStack+Migration.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sources/DataStack+Migration.swift b/Sources/DataStack+Migration.swift index c6dec22..339c478 100644 --- a/Sources/DataStack+Migration.swift +++ b/Sources/DataStack+Migration.swift @@ -796,6 +796,11 @@ public extension DataStack { throw CoreStoreError(error) } + let externalStorageDirName = "." + fileURL.deletingPathExtension().lastPathComponent + "_SUPPORT" + let temporaryExtenralStorageURL = temporaryDirectoryURL.appendingPathComponent( + externalStorageDirName, + isDirectory: true + ) do { try fileManager.replaceItem( @@ -806,11 +811,23 @@ public extension DataStack { resultingItemURL: nil ) + if fileManager.fileExists(atPath: temporaryExtenralStorageURL.path) { + let extenralStorageURL = fileURL.deletingLastPathComponent().appendingPathComponent(externalStorageDirName, isDirectory: true) + try fileManager.replaceItem( + at: extenralStorageURL as URL, + withItemAt: temporaryExtenralStorageURL, + backupItemName: nil, + options: [], + resultingItemURL: nil + ) + } + progress.completedUnitCount = progress.totalUnitCount } catch { _ = try? fileManager.removeItem(at: temporaryFileURL) + _ = try? fileManager.removeItem(at: temporaryExtenralStorageURL) throw CoreStoreError(error) } }