Refactoring

This commit is contained in:
Leon Böttger committed 2025-04-04 20:26:09 +02:00
1 parent bb86ebc606
commit ce77e73428
2 files changed
+2 -14

No files matched your search

+1 -13
View File
@@ -471,24 +471,12 @@ public class SaveFilesManager {
for file in files {
let fileName = file.lastPathComponent
var destinationURL = target.appendingPathComponent(fileName)
let destinationURL = target.appendingPathComponent(fileName)
if !filesFinishedDownloading.contains(destinationURL) {
log("File \(file) not finished downloading, skipping")
log("Pending files: \(filesFinishedDownloading)")
continue
}
var counter = 1
let fileExtension = destinationURL.pathExtension
let baseName = destinationURL.deletingPathExtension().lastPathComponent
while fileManager.fileExists(atPath: destinationURL.path) {
let newFileName = "\(baseName)-\(counter)"
let newFileNameWithExtension = fileExtension.isEmpty ? newFileName : "\(newFileName).\(fileExtension)"
destinationURL = target.appendingPathComponent(newFileNameWithExtension)
counter += 1
}
log("Moving file: \(file.lastPathComponent) to \(destinationURL.lastPathComponent)")
try fileManager.copyItem(at: file, to: destinationURL)