|
|
@@ -331,29 +331,30 @@ class DownloadTaskDelegate: TaskDelegate, URLSessionDownloadDelegate {
|
|
|
{
|
|
|
temporaryURL = location
|
|
|
|
|
|
- if let destination = destination {
|
|
|
- let result = destination(location, downloadTask.response as! HTTPURLResponse)
|
|
|
- let destination = result.destinationURL
|
|
|
- let options = result.options
|
|
|
-
|
|
|
- do {
|
|
|
- destinationURL = destination
|
|
|
-
|
|
|
- if options.contains(.removePreviousFile) {
|
|
|
- if FileManager.default.fileExists(atPath: destination.path) {
|
|
|
- try FileManager.default.removeItem(at: destination)
|
|
|
- }
|
|
|
- }
|
|
|
+ guard
|
|
|
+ let destination = destination,
|
|
|
+ let response = downloadTask.response as? HTTPURLResponse
|
|
|
+ else { return }
|
|
|
|
|
|
- if options.contains(.createIntermediateDirectories) {
|
|
|
- let directory = destination.deletingLastPathComponent()
|
|
|
- try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true, attributes: nil)
|
|
|
- }
|
|
|
+ let result = destination(location, response)
|
|
|
+ let destinationURL = result.destinationURL
|
|
|
+ let options = result.options
|
|
|
+
|
|
|
+ self.destinationURL = destinationURL
|
|
|
|
|
|
- try FileManager.default.moveItem(at: location, to: destination)
|
|
|
- } catch {
|
|
|
- self.error = error
|
|
|
+ do {
|
|
|
+ if options.contains(.removePreviousFile), FileManager.default.fileExists(atPath: destinationURL.path) {
|
|
|
+ try FileManager.default.removeItem(at: destinationURL)
|
|
|
}
|
|
|
+
|
|
|
+ if options.contains(.createIntermediateDirectories) {
|
|
|
+ let directory = destinationURL.deletingLastPathComponent()
|
|
|
+ try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ try FileManager.default.moveItem(at: location, to: destinationURL)
|
|
|
+ } catch {
|
|
|
+ self.error = error
|
|
|
}
|
|
|
}
|
|
|
|