Skip to content

Commit

Permalink
Remove file if already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Jun 18, 2024
1 parent d510d8c commit 24e73f2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/MusicLibrary/Process/CopyProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public struct CopyProcessor: LibraryProcessor {
didSet { onProgress(progress) }
}

let fileManager = FileManager.default

var newTracks: [Int: Track] = [:]
for (i, (id, track)) in library.tracks.enumerated() {
let oldURL = track.url
Expand All @@ -64,6 +62,13 @@ public struct CopyProcessor: LibraryProcessor {
progress.update(current: i, message: "Skipping '\(oldURL.lastPathComponent)' (\(reason))...")
} else {
progress.update(current: i, message: "Copying '\(oldURL.lastPathComponent)'...")

let fileManager = FileManager.default

if fileManager.fileExists(atPath: newURL.path) {
try fileManager.removeItem(at: newURL)
}

try fileManager.createDirectory(at: newURL.deletingLastPathComponent(), withIntermediateDirectories: true)
try fileManager.copyItem(at: oldURL, to: newURL)

Expand Down

0 comments on commit 24e73f2

Please sign in to comment.