Skip to content

Commit

Permalink
Merge branch 'release/1.7.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobihagemann committed Feb 20, 2023
2 parents f714b24 + 3d0a916 commit 99fa3b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension PCloud {
private static func createBackgroundClient(withAccessToken accessToken: String, apiHostName: String, sessionIdentifier: String, sharedContainerIdentifier: String?) -> PCloudClient {
let authenticator = OAuthAccessTokenBasedAuthenticator(accessToken: accessToken)
let eventHub = URLSessionEventHub()
var configuration = URLSessionConfiguration.background(withIdentifier: sessionIdentifier)
let configuration = URLSessionConfiguration.background(withIdentifier: sessionIdentifier)
configuration.sharedContainerIdentifier = sharedContainerIdentifier
let session = URLSession(configuration: configuration, delegate: eventHub, delegateQueue: nil)
let foregroundSession = URLSession(configuration: .default, delegate: eventHub, delegateQueue: nil)
Expand Down
17 changes: 12 additions & 5 deletions Sources/CryptomatorCloudAccess/WebDAV/WebDAVProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ public class WebDAVProvider: CloudProvider {
}
return CloudItemMetadata(firstElement, cloudPath: cloudPath)
}.recover { error -> Promise<CloudItemMetadata> in
return self.convertStandardError(error)
if case URLSessionError.httpError(_, statusCode: 405) = error {
// Workaround for: https://github.com/nextcloud/server/issues/34574
return Promise(CloudProviderError.itemNotFound)
} else {
return self.convertStandardError(error)
}
}
}

Expand All @@ -77,7 +82,12 @@ public class WebDAVProvider: CloudProvider {
return initialPromise.then { _ -> CloudItemList in
try self.getCachedCloudItemList(forFolderAt: cloudPath, withPageToken: pageToken)
}.recover { error -> Promise<CloudItemList> in
return self.convertStandardError(error)
if case URLSessionError.httpError(_, statusCode: 405) = error {
// Workaround for: https://github.com/nextcloud/server/issues/34574
return Promise(CloudProviderError.itemNotFound)
} else {
return self.convertStandardError(error)
}
}
}

Expand Down Expand Up @@ -141,7 +151,6 @@ public class WebDAVProvider: CloudProvider {
}
}

// swiftlint:disable:next cyclomatic_complexity
public func uploadFile(from localURL: URL, to cloudPath: CloudPath, replaceExisting: Bool, onTaskCreation: ((URLSessionUploadTask?) -> Void)?) -> Promise<CloudItemMetadata> {
precondition(localURL.isFileURL)
guard let url = URL(cloudPath: cloudPath, relativeTo: client.baseURL) else {
Expand Down Expand Up @@ -170,8 +179,6 @@ public class WebDAVProvider: CloudProvider {
switch error {
case URLSessionError.httpError(_, statusCode: 401):
return Promise(CloudProviderError.unauthorized)
case URLSessionError.httpError(_, statusCode: 405):
return Promise(CloudProviderError.itemTypeMismatch)
case URLSessionError.httpError(_, statusCode: 409), URLSessionError.httpError(_, statusCode: 404):
return Promise(CloudProviderError.parentFolderDoesNotExist)
case URLSessionError.httpError(_, statusCode: 507):
Expand Down
27 changes: 11 additions & 16 deletions Sources/CryptomatorCloudAccess/WebDAV/WebDAVSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,26 @@ class WebDAVClientURLSessionDelegate: NSObject, URLSessionDataDelegate, URLSessi
switch (task, task.response, error) {
case let (dataTask as URLSessionDataTask, httpResponse as HTTPURLResponse, nil):
let runningDataTask = removeRunningDataTask(forKey: dataTask)
HTTPDebugLogger.logResponse(httpResponse, with: runningDataTask?.accumulatedData, or: nil)
guard (200 ... 299).contains(httpResponse.statusCode) else {
runningDataTask?.promise.reject(URLSessionError.httpError(nil, statusCode: httpResponse.statusCode))
return
}
runningDataTask?.fulfillPromise(with: httpResponse)
case let (dataTask as URLSessionDataTask, httpResponse as HTTPURLResponse, .some(error)):
let runningDataTask = removeRunningDataTask(forKey: dataTask)
HTTPDebugLogger.logResponse(httpResponse, with: runningDataTask?.accumulatedData, or: nil)
runningDataTask?.promise.reject(URLSessionError.httpError(error, statusCode: httpResponse.statusCode))
case let (dataTask as URLSessionDataTask, _, .some(error)):
let runningDataTask = removeRunningDataTask(forKey: dataTask)
runningDataTask?.promise.reject(error)
case let (downloadTask as URLSessionDownloadTask, httpResponse as HTTPURLResponse, .some(error)):
let runningDownloadTaskPromise = removeRunningDownloadTask(forKey: downloadTask)
runningDownloadTaskPromise?.promise.reject(URLSessionError.httpError(error, statusCode: httpResponse.statusCode))
let runningDownloadTask = removeRunningDownloadTask(forKey: downloadTask)
HTTPDebugLogger.logResponse(httpResponse, with: nil, or: runningDownloadTask?.localURL)
runningDownloadTask?.promise.reject(URLSessionError.httpError(error, statusCode: httpResponse.statusCode))
case let (downloadTask as URLSessionDownloadTask, _, .some(error)):
let runningDownloadTaskPromise = removeRunningDownloadTask(forKey: downloadTask)
runningDownloadTaskPromise?.promise.reject(error)
let runningDownloadTask = removeRunningDownloadTask(forKey: downloadTask)
runningDownloadTask?.promise.reject(error)
default:
return
}
Expand All @@ -114,6 +117,7 @@ class WebDAVClientURLSessionDelegate: NSObject, URLSessionDataDelegate, URLSessi
return
}
if let response = downloadTask.response as? HTTPURLResponse {
HTTPDebugLogger.logResponse(response, with: nil, or: runningDownloadTask.localURL)
guard (200 ... 299).contains(response.statusCode) else {
runningDownloadTask.promise.reject(URLSessionError.httpError(nil, statusCode: response.statusCode))
return
Expand Down Expand Up @@ -211,10 +215,7 @@ class WebDAVSession {
let webDAVDataTask = WebDAVDataTask(promise: pendingPromise)
delegate?.addRunningDataTask(key: task, value: webDAVDataTask)
task.resume()
return pendingPromise.then { response, data -> Promise<(HTTPURLResponse, Data?)> in
HTTPDebugLogger.logResponse(response, with: data, or: nil)
return Promise((response, data))
}
return pendingPromise
}

func performDownloadTask(with request: URLRequest, to localURL: URL, onTaskCreation: ((URLSessionDownloadTask?) -> Void)?) -> Promise<HTTPURLResponse> {
Expand All @@ -229,10 +230,7 @@ class WebDAVSession {
if onTaskCreation == nil {
task.resume()
}
return pendingPromise.then { response -> Promise<HTTPURLResponse> in
HTTPDebugLogger.logResponse(response, with: nil, or: localURL)
return Promise(response)
}
return pendingPromise
}

func performUploadTask(with request: URLRequest, fromFile fileURL: URL, onTaskCreation: ((URLSessionUploadTask?) -> Void)?) -> Promise<(HTTPURLResponse, Data?)> {
Expand All @@ -247,9 +245,6 @@ class WebDAVSession {
if onTaskCreation == nil {
task.resume()
}
return pendingPromise.then { response, data -> Promise<(HTTPURLResponse, Data?)> in
HTTPDebugLogger.logResponse(response, with: data, or: nil)
return Promise((response, data))
}
return pendingPromise
}
}

0 comments on commit 99fa3b9

Please sign in to comment.