Storage location change (#404)

* Remove LegacyRestorationToken and handling
* Fixes #389 - Migrate and store session data in Application Support instead of Caches
This commit is contained in:
Stefan Ceriu
2023-01-06 10:27:27 +02:00
committed by GitHub
parent e573bc0dd2
commit 34eb835a0b
4 changed files with 30 additions and 43 deletions
+29 -4
View File
@@ -35,12 +35,17 @@ extension URL {
/// The base directory where all session data is stored.
static var sessionsBaseDirectory: URL {
let url = cacheBaseDirectory
.appendingPathComponent("Sessions", isDirectory: true)
let cacheSessionsURL = cacheBaseDirectory.appendingPathComponent("Sessions", isDirectory: true)
let applicationSupportSessionsURL = applicationSupportBaseDirectory.appendingPathComponent("Sessions", isDirectory: true)
#warning("Migration from caches to application support. Remove this in a couple of releases.")
if FileManager.default.directoryExists(at: cacheSessionsURL) {
try? FileManager.default.moveItem(at: cacheSessionsURL, to: applicationSupportSessionsURL)
}
try? FileManager.default.createDirectoryIfNeeded(at: url)
try? FileManager.default.createDirectoryIfNeeded(at: applicationSupportSessionsURL)
return url
return applicationSupportSessionsURL
}
/// The base directory where all cache is stored.
@@ -53,4 +58,24 @@ extension URL {
return url
}
/// The base directory where all application support data is stored.
static var applicationSupportBaseDirectory: URL {
var url = appGroupContainerDirectory
.appendingPathComponent("Library", isDirectory: true)
.appendingPathComponent("Application Support", isDirectory: true)
.appendingPathComponent(InfoPlistReader.target.baseBundleIdentifier, isDirectory: true)
try? FileManager.default.createDirectoryIfNeeded(at: url)
do {
var resourceValues = URLResourceValues()
resourceValues.isExcludedFromBackup = true
try url.setResourceValues(resourceValues)
} catch {
MXLog.error("Failed excluding Application Support from backups")
}
return url
}
}