Skip to content

Commit

Permalink
Merge branch 'release/1.7.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobihagemann committed Feb 16, 2023
2 parents e4618d8 + dca18a9 commit f714b24
Showing 1 changed file with 4 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class GoogleDriveCloudProvider: CloudProvider {
let progress = Progress(totalUnitCount: 1)
return resolvePath(forItemAt: cloudPath).then { item -> Promise<Void> in
progress.becomeCurrent(withPendingUnitCount: 1)
let downloadPromise = self.downloadFile(for: item, to: localURL, onTaskCreation: onTaskCreation)
let downloadPromise = self.downloadFile(for: item, to: localURL)
progress.resignCurrent()
return downloadPromise
}
Expand Down Expand Up @@ -233,7 +233,7 @@ public class GoogleDriveCloudProvider: CloudProvider {
}
}

private func downloadFile(for item: GoogleDriveItem, to localURL: URL, onTaskCreation: ((URLSessionDownloadTask?) -> Void)?) -> Promise<Void> {
private func downloadFile(for item: GoogleDriveItem, to localURL: URL) -> Promise<Void> {
CloudAccessDDLogDebug("GoogleDriveCloudProvider: downloadFile(for: \(item.identifier), to: \(localURL)) called")
guard item.itemType == .file || (item.itemType == .symlink && item.shortcut?.targetItemType == .file) else {
return Promise(CloudProviderError.itemTypeMismatch)
Expand All @@ -247,13 +247,7 @@ public class GoogleDriveCloudProvider: CloudProvider {
progress.totalUnitCount = totalBytesExpectedToWrite // Unnecessary to set several times
progress.completedUnitCount = totalBytesWritten
}
return executeFetcher(fetcher) { sessionTask in
guard let downloadTask = sessionTask as? URLSessionDownloadTask else {
CloudAccessDDLogDebug("GoogleDriveCloudProvider: executeFetcher returned an unexpected URLSessionTask")
return
}
onTaskCreation?(downloadTask)
}
return executeFetcher(fetcher)
}

private func uploadFile(for parentItem: GoogleDriveItem, from localURL: URL, to cloudPath: CloudPath, replaceExisting: Bool) -> Promise<CloudItemMetadata> {
Expand Down Expand Up @@ -558,8 +552,7 @@ public class GoogleDriveCloudProvider: CloudProvider {
}
}

private func executeFetcher(_ fetcher: GTMSessionFetcher, onTaskCreation: @escaping (URLSessionTask?) -> Void) -> Promise<Void> {
var kvoToken: NSKeyValueObservation?
private func executeFetcher(_ fetcher: GTMSessionFetcher) -> Promise<Void> {
return Promise<Void> { fulfill, reject in
self.runningFetchers.append(fetcher)
fetcher.beginFetch { _, error in
Expand All @@ -577,14 +570,6 @@ public class GoogleDriveCloudProvider: CloudProvider {
}
fulfill(())
}
kvoToken = fetcher.observe(\.sessionTask, options: [.new], changeHandler: { _, change in
guard let newValue = change.newValue, let sessionTask = newValue else {
return
}
onTaskCreation(sessionTask)
})
}.always {
kvoToken?.invalidate()
}
}

Expand Down

0 comments on commit f714b24

Please sign in to comment.