summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2023-08-24 12:54:43 +0200
committerAndrej Mihajlov <and@mullvad.net>2023-08-25 12:06:54 +0200
commit28d73680445b15179b89345c7e2f0b22c67f52e8 (patch)
tree2f2f9b2b0f1683d614d9d6f22b39a62c80bb6357
parent082201f0e662b6c2811e5129519d07a527868ad7 (diff)
downloadmullvadvpn-28d73680445b15179b89345c7e2f0b22c67f52e8.tar.xz
mullvadvpn-28d73680445b15179b89345c7e2f0b22c67f52e8.zip
AddressCache: use mutex lock in loadFromFile() and log all errors except when no file on disk
-rw-r--r--ios/MullvadREST/AddressCache.swift23
1 files changed, 15 insertions, 8 deletions
diff --git a/ios/MullvadREST/AddressCache.swift b/ios/MullvadREST/AddressCache.swift
index da27798c9d..774c779fe8 100644
--- a/ios/MullvadREST/AddressCache.swift
+++ b/ios/MullvadREST/AddressCache.swift
@@ -113,17 +113,24 @@ extension REST {
return cache.updatedAt
}
- /// Initializes the cache by reading the a cached file on disk.
+ /// Initializes cache by reading it from file on disk.
///
/// If no cache file is present, a default API endpoint will be selected instead.
public func loadFromFile() {
- // The first time the application is ran, this statement will fail as there is no cache. This is fine.
- // The cache will be filled when either `getCurrentEndpoint` or `setEndpoints()` are called.
- do {
- cache = try fileCache.read()
- } catch {
- logger.debug("Initialized cache with default API endpoint.")
- cache = Self.defaultCachedAddresses
+ cacheLock.withLock {
+ // The first time the application is ran, this statement will fail as there is no cache. This is fine.
+ // The cache will be filled when either `getCurrentEndpoint()` or `setEndpoints()` are called.
+ do {
+ cache = try fileCache.read()
+ } catch {
+ // Log all errors except when file is not on disk.
+ if (error as? CocoaError)?.code != .fileReadNoSuchFile {
+ logger.error(error: error, message: "Failed to load address cache from disk.")
+ }
+
+ logger.debug("Initialized cache with default API endpoint.")
+ cache = Self.defaultCachedAddresses
+ }
}
}
}