Skip to content

Commit

Permalink
Merge branch 'release/1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobihagemann committed Dec 21, 2021
2 parents c4597cc + f99977b commit a033fc7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions Sources/CryptomatorCloudAccess/API/CloudProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public protocol CloudProvider {
- Parameter replaceExisting: If true, overwrite the existing file at `cloudPath`.
- Precondition: `localURL` must be a file URL.
- Postcondition: The file is stored at `cloudPath`.
- Postcondition: The `size` property of the returned metadata is set to the size of the uploaded file in the cloud and must not be `nil`.
- Returns: Promise with the metadata of the uploaded file. If the upload fails, promise is rejected with:
- `CloudProviderError.itemNotFound` if the file does not exist at the `localURL`.
- `CloudProviderError.itemAlreadyExists` if the file already exists at the `cloudPath` with `!replaceExisting` or the cloud provider finds a folder instead of a file at `cloudPath` with `replaceExisting`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ public class GoogleDriveCloudProvider: CloudProvider {
return Promise(CloudProviderError.itemAlreadyExists)
}
let query = GTLRDriveQuery_FilesUpdate.query(withObject: metadata, fileId: item.identifier, uploadParameters: uploadParameters)
query.fields = "id, name, modifiedTime, mimeType"
return Promise(query)
}.recover { error -> GTLRDriveQuery in
guard case CloudProviderError.itemNotFound = error else {
Expand All @@ -407,6 +406,9 @@ public class GoogleDriveCloudProvider: CloudProvider {
metadata.parents = [parentItem.identifier]
let query = GTLRDriveQuery_FilesCreate.query(withObject: metadata, uploadParameters: uploadParameters)
return query
}.then { query -> GTLRDriveQuery in
query.fields = "id, name, modifiedTime, mimeType, size"
return query
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,14 @@ class CloudAccessIntegrationTest: XCTestCase {
print("\(progress.localizedDescription ?? "") (\(progress.localizedAdditionalDescription ?? ""))")
}
progress.becomeCurrent(withPendingUnitCount: 1)
provider.uploadFile(from: initialLocalURL, to: cloudPath, replaceExisting: false).then { _ -> Promise<CloudItemMetadata> in
provider.uploadFile(from: initialLocalURL, to: cloudPath, replaceExisting: false).then { cloudItemMetadata -> Promise<CloudItemMetadata> in
XCTAssertTrue(progress.completedUnitCount >= progress.totalUnitCount)
self.assertReceivedCorrectMetadataAfterUploading(file: initialLocalURL, to: cloudPath, metadata: cloudItemMetadata)
try overwrittenTestContent.write(to: initialLocalURL, atomically: true, encoding: .utf8)
return self.provider.uploadFile(from: initialLocalURL, to: cloudPath, replaceExisting: true)
}.then { _ in
self.provider.downloadFile(from: cloudPath, to: overwrittenLocalURL)
}.then { cloudItemMetadata -> Promise<Void> in
self.assertReceivedCorrectMetadataAfterUploading(file: initialLocalURL, to: cloudPath, metadata: cloudItemMetadata)
return self.provider.downloadFile(from: cloudPath, to: overwrittenLocalURL)
}.then { _ in
self.provider.deleteFile(at: cloudPath)
}.then {
Expand Down Expand Up @@ -969,6 +971,22 @@ class CloudAccessIntegrationTest: XCTestCase {
}
wait(for: [expectation], timeout: 30.0)
}

private func assertReceivedCorrectMetadataAfterUploading(file localURL: URL, to cloudPath: CloudPath, metadata: CloudItemMetadata) {
let localFileSize: Int?
do {
let attributes = try FileManager.default.attributesOfItem(atPath: localURL.path)
localFileSize = attributes[FileAttributeKey.size] as? Int
} catch {
XCTFail("Get local file size failed with error: \(error)")
return
}
XCTAssertEqual(cloudPath, metadata.cloudPath)
XCTAssertEqual(cloudPath.lastPathComponent, metadata.name)
XCTAssertEqual(localFileSize, metadata.size)
XCTAssertNotNil(metadata.size)
XCTAssertEqual(.file, metadata.itemType)
}
}

extension CloudItemMetadata: Comparable {
Expand Down

0 comments on commit a033fc7

Please sign in to comment.