Organize: Skip existing files if not overwriting

Fixes #1484
This commit is contained in:
Jonas Kvinge
2025-12-17 22:58:17 +01:00
parent fe4d9979ce
commit 1c2e87b741
2 changed files with 27 additions and 0 deletions

View File

@@ -206,6 +206,15 @@ void Organize::ProcessSomeFiles() {
if (dest_type != Song::FileType::Unknown) {
// Get the preset
TranscoderPreset preset = Transcoder::PresetForFileType(dest_type);
// Check if the destination file already exists and we're not allowed to overwrite
const QString dest_filename_with_new_ext = Utilities::FiddleFileExtension(task.song_info_.new_filename_, preset.extension_);
if (ShouldSkipFile(dest_filename_with_new_ext)) {
qLog(Debug) << "Skipping" << task.song_info_.song_.url().toLocalFile() << ", destination file already exists";
tasks_complete_++;
continue;
}
qLog(Debug) << "Transcoding with" << preset.name_;
task.transcoded_filename_ = transcoder_->GetFile(task.song_info_.song_.url().toLocalFile(), preset);
@@ -222,6 +231,13 @@ void Organize::ProcessSomeFiles() {
}
}
// Check if the destination file already exists and we're not allowed to overwrite
if (ShouldSkipFile(task.song_info_.new_filename_)) {
qLog(Debug) << "Skipping" << task.song_info_.song_.url().toLocalFile() << ", destination file already exists";
tasks_complete_++;
continue;
}
MusicStorage::CopyJob job;
job.source_ = task.transcoded_filename_.isEmpty() ? task.song_info_.song_.url().toLocalFile() : task.transcoded_filename_;
job.destination_ = task.song_info_.new_filename_;
@@ -292,6 +308,16 @@ void Organize::ProcessSomeFiles() {
}
bool Organize::ShouldSkipFile(const QString &filename) const {
if (overwrite_) {
return false;
}
return QFile::exists(destination_->LocalPath() + QLatin1Char('/') + filename);
}
Song::FileType Organize::CheckTranscode(const Song::FileType original_type) const {
if (original_type == Song::FileType::Stream) return Song::FileType::Unknown;

View File

@@ -94,6 +94,7 @@ class Organize : public QObject {
void SetSongProgress(const float progress, const bool transcoded = false);
void UpdateProgress();
Song::FileType CheckTranscode(const Song::FileType original_type) const;
bool ShouldSkipFile(const QString &filename) const;
private:
struct Task {