diff --git a/ios/Sources/BrowserModel.swift b/ios/Sources/BrowserModel.swift index 4afb665..79075c7 100644 --- a/ios/Sources/BrowserModel.swift +++ b/ios/Sources/BrowserModel.swift @@ -103,7 +103,8 @@ final class BrowserModel: NSObject, ObservableObject, WKNavigationDelegate, WKUI authentication = WebDestination(url: url) } - func removeDownload() { + func removeDownload(expected: URL? = nil) { + if let expected, download?.url != expected, downloadLocation != expected { return } download = nil if let location = downloadLocation { try? FileManager.default.removeItem(at: location.deletingLastPathComponent()) diff --git a/ios/Sources/ContentView.swift b/ios/Sources/ContentView.swift index d7c47db..1b1abae 100644 --- a/ios/Sources/ContentView.swift +++ b/ios/Sources/ContentView.swift @@ -155,7 +155,7 @@ struct ContentView: View { AuthenticationView(destination: destination.url, model: browser) } .sheet(item: $browser.download) { file in - ExportView(url: file.url) { browser.removeDownload() } + ExportView(url: file.url) { browser.removeDownload(expected: file.url) } } } diff --git a/ios/Tests/BrowserModelTests.swift b/ios/Tests/BrowserModelTests.swift index 53bf437..23e9d73 100644 --- a/ios/Tests/BrowserModelTests.swift +++ b/ios/Tests/BrowserModelTests.swift @@ -13,6 +13,18 @@ final class BrowserModelTests: XCTestCase { XCTAssertFalse(model.web.isInspectable) } + @MainActor + func testLateExportCancellationDoesNotEraseAnotherServersDownload() { + let model = BrowserModel() + let previous = URL(fileURLWithPath: "/old-selection.txt") + let current = URL(fileURLWithPath: "/new-selection.txt") + model.download = WebDestination(url: current) + model.removeDownload(expected: previous) + XCTAssertEqual(model.download?.url, current) + model.removeDownload(expected: current) + XCTAssertNil(model.download) + } + @MainActor func testServerErasureReplacesHistoryContext() async { let model = BrowserModel()