From 3756dfa52738eb190b624b9563cedca51343befa Mon Sep 17 00:00:00 2001 From: fmodf Date: Wed, 24 Jul 2024 11:01:31 +0200 Subject: [PATCH] wip --- .../AppCore/Files/DownloadManager.swift | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/ConversationsClassic/AppCore/Files/DownloadManager.swift b/ConversationsClassic/AppCore/Files/DownloadManager.swift index 0df85f9..67bf06e 100644 --- a/ConversationsClassic/AppCore/Files/DownloadManager.swift +++ b/ConversationsClassic/AppCore/Files/DownloadManager.swift @@ -25,18 +25,20 @@ final class DownloadManager { self.downloadQueue.async { self.activeDownloads.remove(url) - if let tempLocalUrl = tempLocalUrl, error == nil { - do { - if FileManager.default.fileExists(atPath: localUrl.path) { - try FileManager.default.removeItem(at: localUrl) - } - try FileManager.default.moveItem(at: tempLocalUrl, to: localUrl) - completion(nil) - } catch let writeError { - completion(writeError) - } - } else { + guard let tempLocalUrl = tempLocalUrl, error == nil else { completion(error) + return + } + + do { + if FileManager.default.fileExists(atPath: localUrl.path) { + try FileManager.default.removeItem(at: localUrl) + } + let data = try Data(contentsOf: tempLocalUrl) + try data.write(to: localUrl) + completion(nil) + } catch let writeError { + completion(writeError) } } }