From f5075bb2d120f2e1e77587cee0971edada7bd8fe Mon Sep 17 00:00:00 2001 From: Tobias Hagemann Date: Mon, 16 Sep 2024 16:01:01 +0200 Subject: [PATCH] Switched Box dependency to fork, supporting background URL sessions --- CryptomatorCloudAccess.xcodeproj/project.pbxproj | 6 +++--- .../xcshareddata/swiftpm/Package.resolved | 8 ++++---- Package.resolved | 6 +++--- Package.swift | 2 +- .../Box/BoxCloudProvider.swift | 15 +++------------ 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/CryptomatorCloudAccess.xcodeproj/project.pbxproj b/CryptomatorCloudAccess.xcodeproj/project.pbxproj index cf1314d..bcbce32 100644 --- a/CryptomatorCloudAccess.xcodeproj/project.pbxproj +++ b/CryptomatorCloudAccess.xcodeproj/project.pbxproj @@ -1890,10 +1890,10 @@ }; B3C72B752BFC798A006F8218 /* XCRemoteSwiftPackageReference "box-swift-sdk-gen" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/box/box-swift-sdk-gen.git"; + repositoryURL = "https://github.com/tobihagemann/box-swift-sdk-gen.git"; requirement = { - kind = upToNextMinorVersion; - minimumVersion = 0.5.0; + kind = exactVersion; + version = "0.5.0-cryptomator"; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/CryptomatorCloudAccess.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/CryptomatorCloudAccess.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index baadeef..9076027 100644 --- a/CryptomatorCloudAccess.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/CryptomatorCloudAccess.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "9cadc7a70613b038fe8d97d191b9a6f48d09309fa0636f36dfa1ef6376591ebc", + "originHash" : "1e544db849a8e8bec5142a55d1c8c095e3af91fce1264266393ab47c4271d671", "pins" : [ { "identity" : "appauth-ios", @@ -31,10 +31,10 @@ { "identity" : "box-swift-sdk-gen", "kind" : "remoteSourceControl", - "location" : "https://github.com/box/box-swift-sdk-gen.git", + "location" : "https://github.com/tobihagemann/box-swift-sdk-gen.git", "state" : { - "revision" : "a6b5793ab4053f9b55b840245ad07c9e3fdae344", - "version" : "0.5.0" + "revision" : "b2bb9db3b4fc5e86807f3c5043bedcab9fdf48f7", + "version" : "0.5.0-cryptomator" } }, { diff --git a/Package.resolved b/Package.resolved index a9e331d..0622fed 100644 --- a/Package.resolved +++ b/Package.resolved @@ -30,10 +30,10 @@ { "identity" : "box-swift-sdk-gen", "kind" : "remoteSourceControl", - "location" : "https://github.com/box/box-swift-sdk-gen.git", + "location" : "https://github.com/tobihagemann/box-swift-sdk-gen.git", "state" : { - "revision" : "a6b5793ab4053f9b55b840245ad07c9e3fdae344", - "version" : "0.5.0" + "revision" : "b2bb9db3b4fc5e86807f3c5043bedcab9fdf48f7", + "version" : "0.5.0-cryptomator" } }, { diff --git a/Package.swift b/Package.swift index e2783e1..75344f4 100644 --- a/Package.swift +++ b/Package.swift @@ -30,7 +30,6 @@ let package = Package( dependencies: [ .package(url: "https://github.com/AzureAD/microsoft-authentication-library-for-objc.git", .upToNextMinor(from: "1.3.0")), .package(url: "https://github.com/aws-amplify/aws-sdk-ios-spm.git", .upToNextMinor(from: "2.34.0")), - .package(url: "https://github.com/box/box-swift-sdk-gen.git", .upToNextMinor(from: "0.5.0")), .package(url: "https://github.com/cryptomator/cryptolib-swift.git", .upToNextMinor(from: "1.1.0")), .package(url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", .upToNextMinor(from: "3.8.0")), .package(url: "https://github.com/google/google-api-objectivec-client-for-rest.git", .upToNextMinor(from: "3.4.0")), @@ -43,6 +42,7 @@ let package = Package( .package(url: "https://github.com/phil1995/dropbox-sdk-obj-c-spm.git", .upToNextMinor(from: "7.2.0")), .package(url: "https://github.com/phil1995/msgraph-sdk-objc-spm.git", .upToNextMinor(from: "1.0.0")), .package(url: "https://github.com/phil1995/msgraph-sdk-objc-models-spm.git", .upToNextMinor(from: "1.3.0")), + .package(url: "https://github.com/tobihagemann/box-swift-sdk-gen.git", exact: "0.5.0-cryptomator"), .package(url: "https://github.com/tobihagemann/JOSESwift.git", exact: "2.4.1-cryptomator") ], targets: [ diff --git a/Sources/CryptomatorCloudAccess/Box/BoxCloudProvider.swift b/Sources/CryptomatorCloudAccess/Box/BoxCloudProvider.swift index 50e8fd7..f492c42 100644 --- a/Sources/CryptomatorCloudAccess/Box/BoxCloudProvider.swift +++ b/Sources/CryptomatorCloudAccess/Box/BoxCloudProvider.swift @@ -245,15 +245,12 @@ public class BoxCloudProvider: CloudProvider { let pendingPromise = Promise.pending() _Concurrency.Task { do { - guard let fileStream = InputStream(url: localURL) else { - throw CloudProviderError.itemNotFound - } let requestBody = UploadFileRequestBody( attributes: UploadFileRequestBodyAttributesField( name: cloudPath.lastPathComponent, parent: UploadFileRequestBodyAttributesParentField(id: parentItem.identifier) ), - file: fileStream + fileURL: localURL ) let files = try await client.uploads.uploadFile(requestBody: requestBody) guard let file = files.entries?.first else { @@ -274,12 +271,9 @@ public class BoxCloudProvider: CloudProvider { let pendingPromise = Promise.pending() _Concurrency.Task { do { - guard let fileStream = InputStream(url: localURL) else { - throw CloudProviderError.itemNotFound - } let requestBody = UploadFileVersionRequestBody( attributes: UploadFileVersionRequestBodyAttributesField(name: cloudPath.lastPathComponent), - file: fileStream + fileURL: localURL ) let files = try await client.uploads.uploadFileVersion(fileId: existingItem.identifier, requestBody: requestBody) guard let file = files.entries?.first else { @@ -329,14 +323,11 @@ public class BoxCloudProvider: CloudProvider { } private func uploadLargeFile(for uploadSession: UploadSession, from localURL: URL, to cloudPath: CloudPath, fileSize: Int) async throws -> CloudItemMetadata { - guard let fileStream = InputStream(url: localURL) else { - throw CloudProviderError.itemNotFound - } guard let uploadPartUrl = uploadSession.sessionEndpoints?.uploadPart, let commitUrl = uploadSession.sessionEndpoints?.commit, let partSize = uploadSession.partSize else { throw BoxSDKError(message: "Failed to retrieve upload session data") } let fileHash = Hash(algorithm: .sha1) - let chunksIterator = Utils.iterateChunks(stream: fileStream, chunkSize: partSize, fileSize: Int64(fileSize)) + let chunksIterator = Utils.iterateChunks(fileURL: localURL, chunkSize: partSize, fileSize: Int64(fileSize)) let results = try await Utils.reduceIterator(iterator: chunksIterator, reducer: client.chunkedUploads.reducer, initialValue: PartAccumulator(lastIndex: -1, parts: [], fileSize: Int64(fileSize), uploadPartUrl: uploadPartUrl, fileHash: fileHash)) let sha1 = await fileHash.digestHash(encoding: "base64") let digest = "\("sha=")\(sha1)"