fix(file-provider): Do not report cancellations as errors

Signed-off-by: Claudio Cambra <[email protected]>
Assisted-by: Codex:GPT-6
Signed-off-by: Claudio Cambra <[email protected]>
This commit is contained in:
Claudio Cambra committed 2026-11-06 00:54:10 +08:00
1 parent f1072b761b
commit ef24d61f5c
2 files changed
+63 -13

No files matched your search

@@ -170,6 +170,15 @@ import OSLog
updatedSyncStateReporting(oldActions: oldActions)
}
func completeSyncAction(_ actionId: UUID, error: Error?) {
if error == nil || (error as? CocoaError)?.code == .userCancelled {
removeSyncAction(actionId)
} else {
insertErrorAction(actionId)
signalEnumerator(completionHandler: { _ in })
}
}
// MARK: - NSFileProviderReplicatedExtension protocol methods
public func item(for identifier: NSFileProviderItemIdentifier, request _: NSFileProviderRequest, completionHandler: @Sendable @escaping (NSFileProviderItem?, Error?) -> Void) -> Progress {
@@ -361,15 +370,10 @@ import OSLog
log: log
)
if error == nil {
if let fileProviderError = error as? NSFileProviderError, fileProviderError.code == .excludedFromSync {
removeSyncAction(actionId)
} else {
if let fileProviderError = error as? NSFileProviderError, fileProviderError.code == .excludedFromSync {
removeSyncAction(actionId)
} else {
insertErrorAction(actionId)
signalEnumerator(completionHandler: { _ in })
}
completeSyncAction(actionId, error: error)
}
logger.debug("Calling item creation completion handler.", [.item: item?.itemIdentifier, .name: item?.filename, .error: error])
@@ -466,12 +470,7 @@ import OSLog
appProxy: app
)
if error != nil {
insertErrorAction(actionId)
signalEnumerator(completionHandler: { _ in })
} else {
removeSyncAction(actionId)
}
completeSyncAction(actionId, error: error)
logger.debug("Calling item modification completion handler.", [.item: item.itemIdentifier, .name: item.filename, .error: error])
completionHandler(modifiedItem ?? item, [], false, error)
@@ -34,6 +34,57 @@ final class ReportCurrentSyncStateTests: NextcloudFileProviderKitTestCase {
XCTAssertEqual(proxy.reportedSyncStatuses, ["SYNC_FINISHED"])
}
func testCompletedOrCancelledActionReportsFinished() {
let errors: [Error?] = [nil, CocoaError(.userCancelled), NSError(domain: NSCocoaErrorDomain, code: NSUserCancelledError)]
for error in errors {
let ext = makeExtension()
let proxy = SyncStatusCapturingAppProxy()
ext.app = proxy
let actionId = UUID()
ext.insertSyncAction(actionId)
ext.completeSyncAction(actionId, error: error)
XCTAssertEqual(proxy.reportedSyncStatuses, ["SYNC_STARTED", "SYNC_FINISHED"])
XCTAssertTrue(ext.syncActions.isEmpty)
XCTAssertTrue(ext.errorActions.isEmpty)
}
}
func testFailedActionReportsFailure() {
let ext = makeExtension()
let proxy = SyncStatusCapturingAppProxy()
ext.app = proxy
let actionId = UUID()
ext.insertSyncAction(actionId)
ext.completeSyncAction(actionId, error: NSFileProviderError(.serverUnreachable))
XCTAssertEqual(proxy.reportedSyncStatuses, ["SYNC_STARTED", "SYNC_FAILED"])
XCTAssertTrue(ext.syncActions.isEmpty)
}
func testCancelledActionPreservesOtherActionsAndFailures() {
let ext = makeExtension()
let proxy = SyncStatusCapturingAppProxy()
ext.app = proxy
let cancelledId = UUID()
let runningId = UUID()
let failedId = UUID()
ext.insertSyncAction(cancelledId)
ext.insertSyncAction(runningId)
ext.insertSyncAction(failedId)
ext.completeSyncAction(failedId, error: NSFileProviderError(.serverUnreachable))
ext.completeSyncAction(cancelledId, error: CocoaError(.userCancelled))
XCTAssertEqual(ext.syncActions, [runningId])
XCTAssertEqual(ext.errorActions, [failedId])
XCTAssertEqual(proxy.reportedSyncStatuses, ["SYNC_STARTED"])
ext.completeSyncAction(runningId, error: nil)
XCTAssertEqual(proxy.reportedSyncStatuses, ["SYNC_STARTED", "SYNC_FAILED"])
}
func testReportsStartedWhileSyncing() {
let ext = makeExtension()
let proxy = SyncStatusCapturingAppProxy()