Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cryptomator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
4A447E3D25BF1AD400D9520D /* FolderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A447E3C25BF1AD400D9520D /* FolderCell.swift */; };
4A447E4D25BF1E8B00D9520D /* FileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A447E4C25BF1E8B00D9520D /* FileCell.swift */; };
4A447E5625BF1F6A00D9520D /* CloudItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A447E5525BF1F6A00D9520D /* CloudItemCell.swift */; };
4A4490022BCD449000449002 /* FileProviderAdapterResumeOrderingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A4490012BCD449000449001 /* FileProviderAdapterResumeOrderingTests.swift */; };
4A49FABA271ECA530069A0CC /* ItemEnumerationTaskRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A49FAB9271ECA530069A0CC /* ItemEnumerationTaskRecord.swift */; };
4A49FABC271ECB680069A0CC /* ItemEnumerationTaskDBManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A49FABB271ECB680069A0CC /* ItemEnumerationTaskDBManager.swift */; };
4A49FABE271ECDE80069A0CC /* ItemEnumerationTaskManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A49FABD271ECDE80069A0CC /* ItemEnumerationTaskManagerTests.swift */; };
Expand Down Expand Up @@ -674,6 +675,7 @@
4A447E3C25BF1AD400D9520D /* FolderCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderCell.swift; sourceTree = "<group>"; };
4A447E4C25BF1E8B00D9520D /* FileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileCell.swift; sourceTree = "<group>"; };
4A447E5525BF1F6A00D9520D /* CloudItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloudItemCell.swift; sourceTree = "<group>"; };
4A4490012BCD449000449001 /* FileProviderAdapterResumeOrderingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderAdapterResumeOrderingTests.swift; sourceTree = "<group>"; };
4A49FAB9271ECA530069A0CC /* ItemEnumerationTaskRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemEnumerationTaskRecord.swift; sourceTree = "<group>"; };
4A49FABB271ECB680069A0CC /* ItemEnumerationTaskDBManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemEnumerationTaskDBManager.swift; sourceTree = "<group>"; };
4A49FABD271ECDE80069A0CC /* ItemEnumerationTaskManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemEnumerationTaskManagerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1634,6 +1636,7 @@
4A248230266FB799002D9F59 /* FileProviderAdapterStartProvidingItemTests.swift */,
4A8F14A1266A302A00ADBCE4 /* FileProviderAdapterTestCase.swift */,
4A8CF8C027E906D7004CE880 /* FileProviderAdapterImportDirectoryTests.swift */,
4A4490012BCD449000449001 /* FileProviderAdapterResumeOrderingTests.swift */,
);
path = FileProviderAdapter;
sourceTree = "<group>";
Expand Down Expand Up @@ -2743,6 +2746,7 @@
4AEECD39279EB1EB00C6E2B5 /* FileProviderEnumeratorTests.swift in Sources */,
4ADC66BF27A44558002E6CC7 /* XCTestCase+Promises.swift in Sources */,
4A8CF8C127E906D7004CE880 /* FileProviderAdapterImportDirectoryTests.swift in Sources */,
4A4490022BCD449000449002 /* FileProviderAdapterResumeOrderingTests.swift in Sources */,
4AB1D4F227D20510009060AB /* DocumentStorageURLProviderMock.swift in Sources */,
4A797F8F24AC6731007DDBE1 /* FileProviderItemTests.swift in Sources */,
4A9C8E0127A0104E000063E4 /* EnumerationSignalingMock.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions CryptomatorFileProvider/FileProviderAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ public class FileProviderAdapter: FileProviderAdapterType {
} else {
DDLogInfo("Successfully registered URLSessionUploadTask for identifier: \(itemIdentifier)")
}
urlSessionTask.resume()
})
urlSessionTask.resume()
})
} catch {
completionHandler?(error)
Expand Down Expand Up @@ -788,8 +788,8 @@ public class FileProviderAdapter: FileProviderAdapterType {
} else {
DDLogInfo("Successfully registered URLSessionTask for identifier: \(identifier)")
}
urlSessionTask.resume()
})
urlSessionTask.resume()
})
} catch {
return Promise(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// FileProviderAdapterResumeOrderingTests.swift
// CryptomatorFileProviderTests
//
// Created by Tobias Hagemann on 17.06.26.
// Copyright © 2026 Skymatic GmbH. All rights reserved.
//

import CryptomatorCloudAccessCore
import FileProvider
import Foundation
import XCTest
@testable import CryptomatorCommonCore
@testable import CryptomatorFileProvider

/// A WebDAV transfer task must be resumed only *after* `NSFileProviderManager.register(_:forItemWithIdentifier:)`
/// completes. Resuming beforehand starts the transfer before the system is tracking it, which loses progress
/// reporting and can leave the File Provider hanging (issue #449). Registration must still resume on failure so a
/// transfer is never silently dropped (issue #272).
final class FileProviderAdapterResumeOrderingTests: FileProviderAdapterTestCase {
private let downloadIdentifier = NSFileProviderItemIdentifier(domainIdentifier: .test, itemID: 2)
private let uploadIdentifier = NSFileProviderItemIdentifier(domainIdentifier: .test, itemID: 3)

override func setUpWithError() throws {
try super.setUpWithError()
metadataManagerMock.cachedMetadata[2] = ItemMetadata(id: 2, name: "download.txt", type: .file, size: 100, parentID: NSFileProviderItemIdentifier.rootContainerDatabaseValue, lastModifiedDate: nil, statusCode: .isUploaded, cloudPath: CloudPath("/download.txt"), isPlaceholderItem: false)
metadataManagerMock.cachedMetadata[3] = ItemMetadata(id: 3, name: "upload.txt", type: .file, size: 100, parentID: NSFileProviderItemIdentifier.rootContainerDatabaseValue, lastModifiedDate: nil, statusCode: .isUploading, cloudPath: CloudPath("/upload.txt"), isPlaceholderItem: false)
}

// MARK: - Download

func testDownloadResumesTaskOnlyAfterRegistrationCompletes() throws {
let adapter = createFullyMockedAdapter()
let task = ResumeRecordingURLSessionTask()
_ = adapter.downloadFile(with: downloadIdentifier, to: URL(fileURLWithPath: "/dev/null"))
let onURLSessionTaskCreation = try XCTUnwrap(downloadTaskManagerMock.lastOnURLSessionTaskCreation)

onURLSessionTaskCreation(task)

XCTAssertTrue(taskRegistratorMock.registerForItemWithIdentifierCompletionHandlerCalled)
XCTAssertEqual(task.resumeCallCount, 0, "the download must not be resumed before registration completes")

let completion = try XCTUnwrap(taskRegistratorMock.registerForItemWithIdentifierCompletionHandlerReceivedArguments?.completion)
completion(nil)
XCTAssertEqual(task.resumeCallCount, 1)
}

func testDownloadResumesTaskEvenWhenRegistrationFails() throws {
let adapter = createFullyMockedAdapter()
let task = ResumeRecordingURLSessionTask()
_ = adapter.downloadFile(with: downloadIdentifier, to: URL(fileURLWithPath: "/dev/null"))
let onURLSessionTaskCreation = try XCTUnwrap(downloadTaskManagerMock.lastOnURLSessionTaskCreation)

onURLSessionTaskCreation(task)
let completion = try XCTUnwrap(taskRegistratorMock.registerForItemWithIdentifierCompletionHandlerReceivedArguments?.completion)
completion(NSError(domain: "test", code: 1))

XCTAssertEqual(task.resumeCallCount, 1, "a failed registration must still resume the download")
}

// MARK: - Upload

func testUploadResumesTaskOnlyAfterRegistrationCompletes() throws {
let adapter = createFullyMockedAdapter()
let task = ResumeRecordingURLSessionTask()
let taskRecord = UploadTaskRecord(correspondingItem: 3, lastFailedUploadDate: nil, uploadErrorCode: nil, uploadErrorDomain: nil, uploadStartedAt: Date())

_ = adapter.uploadFile(taskRecord: taskRecord, itemIdentifier: uploadIdentifier)
let onURLSessionTaskCreation = try XCTUnwrap(uploadTaskManagerMock.getTaskForOnURLSessionTaskCreationReceivedArguments?.onURLSessionTaskCreation)

onURLSessionTaskCreation(task)
XCTAssertEqual(task.resumeCallCount, 0, "the upload must not be resumed before registration completes")

let completion = try XCTUnwrap(taskRegistratorMock.registerForItemWithIdentifierCompletionHandlerReceivedArguments?.completion)
completion(nil)
XCTAssertEqual(task.resumeCallCount, 1)
}

func testUploadResumesTaskEvenWhenRegistrationFails() throws {
let adapter = createFullyMockedAdapter()
let task = ResumeRecordingURLSessionTask()
let taskRecord = UploadTaskRecord(correspondingItem: 3, lastFailedUploadDate: nil, uploadErrorCode: nil, uploadErrorDomain: nil, uploadStartedAt: Date())

_ = adapter.uploadFile(taskRecord: taskRecord, itemIdentifier: uploadIdentifier)
let onURLSessionTaskCreation = try XCTUnwrap(uploadTaskManagerMock.getTaskForOnURLSessionTaskCreationReceivedArguments?.onURLSessionTaskCreation)

onURLSessionTaskCreation(task)
let completion = try XCTUnwrap(taskRegistratorMock.registerForItemWithIdentifierCompletionHandlerReceivedArguments?.completion)
completion(NSError(domain: "test", code: 1))

XCTAssertEqual(task.resumeCallCount, 1, "a failed registration must still resume the upload")
}
}

private final class ResumeRecordingURLSessionTask: URLSessionTask, @unchecked Sendable {
private(set) var resumeCallCount = 0

override func resume() {
resumeCallCount += 1
}

override func cancel() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,10 @@ class CloudTaskExecutorTestCase: XCTestCase {

class DownloadTaskManagerMock: DownloadTaskManager {
var removedTasks = [DownloadTaskRecord]()
var lastOnURLSessionTaskCreation: URLSessionTaskCreationClosure?

func createTask(for item: ItemMetadata, replaceExisting: Bool, localURL: URL, onURLSessionTaskCreation: CryptomatorFileProvider.URLSessionTaskCreationClosure?) throws -> DownloadTask {
lastOnURLSessionTaskCreation = onURLSessionTaskCreation
let taskRecord = DownloadTaskRecord(correspondingItem: item.id!, replaceExisting: replaceExisting, localURL: localURL)
return DownloadTask(taskRecord: taskRecord, itemMetadata: item, onURLSessionTaskCreation: onURLSessionTaskCreation)
}
Expand Down
Loading