Skip to content

Commit 86347f2

Browse files
committed
Merge branch 'release/1.6.0-alpha2' into main
2 parents 5152561 + 0ca0d57 commit 86347f2

File tree

43 files changed

+1552
-633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1552
-633
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jobs:
77
build:
88
name: Build and test
99
runs-on: macos-latest
10+
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
1011
steps:
1112
- uses: actions/checkout@v2
1213
- uses: actions/cache@v2

.swiftformat

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# file options
2-
3-
--exclude Pods
4-
51
# format options
62

73
--commas inline
4+
--ifdef no-indent
85
--importgrouping testable-bottom
96
--indent tab
107
--self init-only

CloudAccessPrivate/Sources/CloudAccessPrivate/GoogleDrive/GoogleDriveCloudAuthenticator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public enum GoogleDriveAuthenticationError: Error {
1616
case userCanceled
1717
}
1818

19-
public class GoogleDriveCloudAuthenticator {
19+
public enum GoogleDriveCloudAuthenticator {
2020
private static let scopes = [kGTLRAuthScopeDrive]
2121
public static var currentAuthorizationFlow: OIDExternalUserAgentSession?
2222

CloudAccessPrivate/Sources/CloudAccessPrivateCore/CryptomatorConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
import Foundation
10-
public struct CryptomatorConstants {
10+
public enum CryptomatorConstants {
1111
public static let appGroupName = "group.com.setolabs.Cryptomator"
1212
public static let mainAppBundleId = "com.setolabs.Cryptomator"
1313
}

CloudAccessPrivate/Sources/CloudAccessPrivateCore/Dropbox/DropboxClientSetup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99
import ObjectiveDropboxOfficial
10-
public class DropboxClientSetup {
10+
public enum DropboxClientSetup {
1111
private static var firstTimeInit = true
1212
public static func oneTimeSetup() {
1313
if firstTimeInit {

CloudAccessPrivate/Sources/CloudAccessPrivateCore/Dropbox/DropboxCloudProvider.swift

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,28 @@ public class DropboxCloudProvider: CloudProvider {
5757
guard let authorizedClient = credential.authorizedClient else {
5858
return Promise(CloudProviderError.unauthorized)
5959
}
60+
let progress = Progress(totalUnitCount: 1)
6061
return retryWithExponentialBackoff({
61-
self.downloadFile(from: cloudPath, to: localURL, with: authorizedClient)
62-
}, condition: shouldRetryForError)
62+
progress.becomeCurrent(withPendingUnitCount: 1)
63+
let downloadPromise = self.downloadFile(from: cloudPath, to: localURL, with: authorizedClient)
64+
progress.resignCurrent()
65+
return downloadPromise
66+
}, condition: shouldRetryForError).recover { error -> Promise<Void> in
67+
// Currently we get a 409 (requestError) instead of a 404 (routeError) error when we download a file that does not exist.
68+
// We also get this when a download was performed on a folder.
69+
// Therefore, we currently need to check if there is a folder on the given CloudPath.
70+
71+
guard case CloudProviderError.itemNotFound = error else {
72+
return Promise(error)
73+
}
74+
return self.checkForItemExistence(at: cloudPath).then { itemExists in
75+
if itemExists {
76+
return Promise(CloudProviderError.itemTypeMismatch)
77+
} else {
78+
return Promise(error)
79+
}
80+
}
81+
}
6382
}
6483

6584
/**
@@ -84,12 +103,23 @@ public class DropboxCloudProvider: CloudProvider {
84103
guard localItemType == .file else {
85104
return Promise(CloudProviderError.itemTypeMismatch)
86105
}
106+
let progress = Progress(totalUnitCount: 1)
87107
let mode = replaceExisting ? DBFILESWriteMode(overwrite: ()) : nil
88108
let fileSize = attributes[FileAttributeKey.size] as? Int ?? 157_286_400
89109
if fileSize >= 157_286_400 {
90-
return retryWithExponentialBackoff({ self.uploadBigFile(from: localURL, to: cloudPath, mode: mode, with: authorizedClient) }, condition: shouldRetryForError)
110+
return retryWithExponentialBackoff({
111+
progress.becomeCurrent(withPendingUnitCount: 1)
112+
let uploadPromise = self.uploadBigFile(from: localURL, to: cloudPath, mode: mode, with: authorizedClient)
113+
progress.resignCurrent()
114+
return uploadPromise
115+
}, condition: shouldRetryForError)
91116
} else {
92-
return retryWithExponentialBackoff({ self.uploadSmallFile(from: localURL, to: cloudPath, mode: mode, with: authorizedClient) }, condition: shouldRetryForError)
117+
return retryWithExponentialBackoff({
118+
progress.becomeCurrent(withPendingUnitCount: 1)
119+
let uploadPromise = self.uploadSmallFile(from: localURL, to: cloudPath, mode: mode, with: authorizedClient)
120+
progress.resignCurrent()
121+
return uploadPromise
122+
}, condition: shouldRetryForError)
93123
}
94124
}
95125

@@ -302,7 +332,14 @@ public class DropboxCloudProvider: CloudProvider {
302332
return
303333
}
304334
}
305-
reject(self.convertRequestErrorToDropboxError(requestError))
335+
let dropboxError = self.convertRequestErrorToDropboxError(requestError)
336+
// Currently we get a 409 (requestError) instead of a 404 (routeError) error when we download a file that does not exist.
337+
// Until this is fixed by Dropbox, this workaround is used.
338+
if dropboxError == .httpError, requestError.statusCode == 409 {
339+
reject(CloudProviderError.itemNotFound)
340+
return
341+
}
342+
reject(dropboxError)
306343
return
307344
}
308345
fulfill(())
@@ -313,8 +350,12 @@ public class DropboxCloudProvider: CloudProvider {
313350
// uploadFile
314351

315352
private func uploadBigFile(from localURL: URL, to cloudPath: CloudPath, mode: DBFILESWriteMode?, with client: DBUserClient) -> Promise<CloudItemMetadata> {
353+
let progress = Progress(totalUnitCount: 1)
316354
return ensureParentFolderExists(for: cloudPath).then {
317-
self.batchUploadSingleFile(from: localURL, to: cloudPath, mode: mode, with: client)
355+
progress.becomeCurrent(withPendingUnitCount: 1)
356+
let uploadPromise = self.batchUploadSingleFile(from: localURL, to: cloudPath, mode: mode, with: client)
357+
progress.resignCurrent()
358+
return uploadPromise
318359
}
319360
}
320361

@@ -376,8 +417,12 @@ public class DropboxCloudProvider: CloudProvider {
376417
}
377418

378419
private func uploadSmallFile(from localURL: URL, to cloudPath: CloudPath, mode: DBFILESWriteMode?, with client: DBUserClient) -> Promise<CloudItemMetadata> {
379-
return ensureParentFolderExists(for: cloudPath).then {
380-
self.uploadFileAfterParentCheck(from: localURL, to: cloudPath, mode: mode, with: client)
420+
let progress = Progress(totalUnitCount: 1)
421+
return ensureParentFolderExists(for: cloudPath).then { _ -> Promise<CloudItemMetadata> in
422+
progress.becomeCurrent(withPendingUnitCount: 1)
423+
let uploadPromise = self.uploadFileAfterParentCheck(from: localURL, to: cloudPath, mode: mode, with: client)
424+
progress.resignCurrent()
425+
return uploadPromise
381426
}
382427
}
383428

CloudAccessPrivate/Sources/CloudAccessPrivateCore/GoogleDrive/GoogleDriveCloudProvider.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ public class GoogleDriveCloudProvider: CloudProvider {
5757
if FileManager.default.fileExists(atPath: localURL.path) {
5858
return Promise(CloudProviderError.itemAlreadyExists)
5959
}
60-
return resolvePath(forFileAt: cloudPath).then { identifier in
61-
self.downloadFile(withIdentifier: identifier, from: cloudPath, to: localURL)
60+
let progress = Progress(totalUnitCount: 1)
61+
return resolvePath(forFileAt: cloudPath).then { identifier -> Promise<Void> in
62+
progress.becomeCurrent(withPendingUnitCount: 1)
63+
let downloadPromise = self.downloadFile(withIdentifier: identifier, from: cloudPath, to: localURL)
64+
progress.resignCurrent()
65+
return downloadPromise
6266
}
6367
}
6468

@@ -73,10 +77,10 @@ public class GoogleDriveCloudProvider: CloudProvider {
7377
if isDirectory.boolValue {
7478
return Promise(CloudProviderError.itemTypeMismatch)
7579
}
80+
let progress = Progress(totalUnitCount: -1)
7681
return resolveParentPath(for: cloudPath).then { parentIdentfier in
7782
self.createFileUploadQuery(from: localURL, to: cloudPath, parentIdentifier: parentIdentfier, replaceExisting: replaceExisting)
7883
}.then { query -> Promise<Any> in
79-
let progress = Progress(totalUnitCount: -1)
8084
query.executionParameters.uploadProgressBlock = { _, totalBytesUploaded, totalBytesExpectedToUpload in
8185
progress.totalUnitCount = Int64(totalBytesExpectedToUpload)
8286
progress.completedUnitCount = Int64(totalBytesUploaded)
@@ -101,12 +105,12 @@ public class GoogleDriveCloudProvider: CloudProvider {
101105
public func createFolder(at cloudPath: CloudPath) -> Promise<Void> {
102106
let foldername = cloudPath.lastPathComponent
103107
return Promise<Void>(on: .global()) { fulfill, reject in
104-
let parentIdentifier = try await(self.resolveParentPath(for: cloudPath))
108+
let parentIdentifier = try await (self.resolveParentPath(for: cloudPath))
105109
do {
106-
_ = try await(self.getFirstIdentifier(forItemWithName: foldername, itemType: .folder, inFolderWithId: parentIdentifier))
110+
_ = try await (self.getFirstIdentifier(forItemWithName: foldername, itemType: .folder, inFolderWithId: parentIdentifier))
107111
reject(CloudProviderError.itemAlreadyExists)
108112
} catch CloudProviderError.itemNotFound {
109-
_ = try await(self.createFolder(at: cloudPath, withParentIdentifier: parentIdentifier))
113+
_ = try await (self.createFolder(at: cloudPath, withParentIdentifier: parentIdentifier))
110114
fulfill(())
111115
} catch CloudProviderError.itemTypeMismatch {
112116
reject(CloudProviderError.itemAlreadyExists)
@@ -515,7 +519,7 @@ public class GoogleDriveCloudProvider: CloudProvider {
515519
for i in startIndex ..< endIndex {
516520
let itemName = endCloudPath.pathComponents[i]
517521
currentURL = currentURL.appendingPathComponent(itemName)
518-
parentIdentifier = try await(self.getFirstIdentifier(forItemWithName: itemName, itemType: .folder, inFolderWithId: parentIdentifier))
522+
parentIdentifier = try await (self.getFirstIdentifier(forItemWithName: itemName, itemType: .folder, inFolderWithId: parentIdentifier))
519523
try self.cloudIdentifierCache?.cacheIdentifier(parentIdentifier, for: currentURL)
520524
}
521525
fulfill(parentIdentifier)

CloudAccessPrivate/Sources/CloudAccessPrivateCore/GoogleDrive/GoogleDriveCredential.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public class GoogleDriveCredential {
3636
driveService.isRetryEnabled = true
3737
driveService.retryBlock = { _, suggestedWillRetry, fetchError in
3838
if let fetchError = fetchError as NSError? {
39-
if fetchError.domain == kGTMSessionFetcherStatusDomain || fetchError.code == GoogleDriveConstants.googleDriveErrorCodeForbidden {
39+
if fetchError.domain != kGTMSessionFetcherStatusDomain || fetchError.code != GoogleDriveConstants.googleDriveErrorCodeForbidden {
4040
return suggestedWillRetry
4141
}
42-
guard let data = fetchError.userInfo["data"] as? Data, let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let error = json["error"] else {
42+
guard let data = fetchError.userInfo["data"] as? Data, let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let error = json["error"] as? [String: Any] else {
4343
return suggestedWillRetry
4444
}
45-
let googleDriveError = GTLRErrorObject(json: ["error": error])
45+
let googleDriveError = GTLRErrorObject(json: error)
4646
guard let errorItem = googleDriveError.errors?.first else {
4747
return suggestedWillRetry
4848
}

CloudAccessPrivate/Sources/CloudAccessPrivateCore/LocalFileSystem/LocalFileSystemBookmarkManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
import Foundation
10-
public class LocalFileSystemBookmarkManager {
10+
public enum LocalFileSystemBookmarkManager {
1111
public static func getBookmarkedRootURL(for accountUID: String) throws -> URL? {
1212
guard let bookmarkData = CryptomatorKeychain.localFileSystem.getAsData(accountUID) else {
1313
return nil
@@ -31,7 +31,7 @@ public class LocalFileSystemBookmarkManager {
3131
try CryptomatorKeychain.localFileSystem.set(accountUID, value: bookmarkData)
3232
}
3333

34-
public static func removeBookmarkedRootURL(for accountUID: String) throws{
34+
public static func removeBookmarkedRootURL(for accountUID: String) throws {
3535
try CryptomatorKeychain.localFileSystem.delete(accountUID)
3636
}
3737
}

CloudAccessPrivate/Sources/CloudAccessPrivateCore/Manager/VaultAccountManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public class VaultAccountManager {
7070
}
7171

7272
public func getAllAccounts() throws -> [VaultAccount] {
73-
try dbPool.read{ db in
73+
try dbPool.read { db in
7474
try VaultAccount.fetchAll(db)
7575
}
7676
}
77-
78-
//only for prototype
77+
78+
// only for prototype
7979
public func getAllVaultUIDs(with delegateAccountUID: String) throws -> [String] {
8080
let accounts: [VaultAccount] = try dbPool.read { db in
8181
return try VaultAccount

0 commit comments

Comments
 (0)