diff options
| author | Emīls <emils@mullvad.net> | 2026-02-05 15:28:00 +0100 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2026-02-05 15:28:00 +0100 |
| commit | 1b4f5ec075153d0080ab991f327fe66509faac33 (patch) | |
| tree | 8d9064bf9ac13cb2d5ae41d22affd4fd7f3bc6d2 | |
| parent | ae9d45f33de3e458fd51c98203b7769bc4f96e03 (diff) | |
| download | mullvadvpn-ios-bug-bash-02-05.tar.xz mullvadvpn-ios-bug-bash-02-05.zip | |
Hotfix deadlock on iOS17ios-bug-bash-02-05
| -rw-r--r-- | ios/MullvadTypes/FileCache.swift | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ios/MullvadTypes/FileCache.swift b/ios/MullvadTypes/FileCache.swift index 3e1a93d0d4..78c19d9db1 100644 --- a/ios/MullvadTypes/FileCache.swift +++ b/ios/MullvadTypes/FileCache.swift @@ -32,6 +32,8 @@ public final class FileCache<Content: Codable>: NSObject, FileCacheProtocol, NSF lazy var coordinator = NSFileCoordinator(filePresenter: self) + private var currentlyClearing = false + public init(fileURL: URL) { self.fileURL = fileURL super.init() @@ -91,6 +93,18 @@ public final class FileCache<Content: Codable>: NSObject, FileCacheProtocol, NSF public func clear() throws { lock.lock() defer { lock.unlock() } + + // On iOS 17, NSFileCoordinator delivers presenter callbacks to self even when + // self is passed as the filePresenter. Temporarily unregister to avoid deadlock. + if #available(iOS 18, *) {} else { + NSFileCoordinator.removeFilePresenter(self) + } + defer { + if #available(iOS 18, *) {} else { + NSFileCoordinator.addFilePresenter(self) + } + } + try coordinator.coordinate(writingItemAt: fileURL, options: [.forDeleting]) { fileURL in try FileManager.default.removeItem(at: fileURL) } |
