This commit is contained in:
fmodf 2024-07-24 11:01:31 +02:00
parent 86745dc87d
commit 3756dfa527

View file

@ -25,19 +25,21 @@ final class DownloadManager {
self.downloadQueue.async {
self.activeDownloads.remove(url)
if let tempLocalUrl = tempLocalUrl, error == nil {
guard let tempLocalUrl = tempLocalUrl, error == nil else {
completion(error)
return
}
do {
if FileManager.default.fileExists(atPath: localUrl.path) {
try FileManager.default.removeItem(at: localUrl)
}
try FileManager.default.moveItem(at: tempLocalUrl, to: localUrl)
let data = try Data(contentsOf: tempLocalUrl)
try data.write(to: localUrl)
completion(nil)
} catch let writeError {
completion(writeError)
}
} else {
completion(error)
}
}
}
task.resume()