mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,17 +50,6 @@ class KeychainController: KeychainControllerProtocol {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Handle the previous restoration token format as we don't want users to have to log in again
|
||||
// It will automatically be updated to the new version after login
|
||||
if let legacyRestorationToken = try? JSONDecoder().decode(LegacyRestorationToken.self, from: tokenData) {
|
||||
return .init(session: .init(accessToken: legacyRestorationToken.session.accessToken,
|
||||
refreshToken: nil,
|
||||
userId: legacyRestorationToken.session.userId,
|
||||
deviceId: legacyRestorationToken.session.deviceId,
|
||||
homeserverUrl: legacyRestorationToken.homeURL,
|
||||
isSoftLogout: legacyRestorationToken.isSoftLogout ?? false))
|
||||
}
|
||||
|
||||
return try JSONDecoder().decode(RestorationToken.self, from: tokenData)
|
||||
} catch {
|
||||
MXLog.error("Failed retrieving user restore token")
|
||||
|
||||
@@ -46,31 +46,3 @@ extension MatrixRustSDK.Session: Codable {
|
||||
case accessToken, refreshToken, userId, deviceId, homeserverUrl, isSoftLogout
|
||||
}
|
||||
}
|
||||
|
||||
#warning("Remove this in a couple of releases - sceriu 03.11.2022")
|
||||
struct LegacyRestorationToken: Decodable {
|
||||
let isGuest: Bool?
|
||||
let isSoftLogout: Bool?
|
||||
let homeURL: String
|
||||
let session: Session
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case isGuest = "is_guest"
|
||||
case isSoftLogout = "is_soft_logout"
|
||||
case homeURL = "homeurl"
|
||||
case session
|
||||
}
|
||||
|
||||
struct Session: Decodable {
|
||||
let accessToken: String
|
||||
let userId: String
|
||||
let deviceId: String
|
||||
|
||||
// swiftlint:disable:next nesting
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case accessToken = "access_token"
|
||||
case userId = "user_id"
|
||||
case deviceId = "device_id"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user