CollectionWatcher: Only start transaction with scan on startup

Fixes #1469
This commit is contained in:
Jonas Kvinge 2024-08-03 00:44:47 +02:00
parent 17e88bb97d
commit ff6e93fc15
1 changed files with 19 additions and 15 deletions

View File

@ -421,6 +421,12 @@ void CollectionWatcher::AddDirectory(const CollectionDirectory &dir, const Colle
last_scan_time_ = QDateTime::currentSecsSinceEpoch(); last_scan_time_ = QDateTime::currentSecsSinceEpoch();
} }
else { else {
if (monitor_) {
for (const CollectionSubdirectory &subdir : subdirs) {
AddWatch(dir, subdir.path);
}
}
if (scan_on_startup_) {
// We can do an incremental scan - looking at the mtimes of each subdirectory and only rescan if the directory has changed. // We can do an incremental scan - looking at the mtimes of each subdirectory and only rescan if the directory has changed.
ScanTransaction transaction(this, dir.id, true, false, mark_songs_unavailable_); ScanTransaction transaction(this, dir.id, true, false, mark_songs_unavailable_);
QMap<QString, quint64> subdir_files_count; QMap<QString, quint64> subdir_files_count;
@ -429,14 +435,12 @@ void CollectionWatcher::AddDirectory(const CollectionDirectory &dir, const Colle
transaction.AddToProgressMax(files_count); transaction.AddToProgressMax(files_count);
for (const CollectionSubdirectory &subdir : subdirs) { for (const CollectionSubdirectory &subdir : subdirs) {
if (stop_requested_ || abort_requested_) break; if (stop_requested_ || abort_requested_) break;
ScanSubdirectory(subdir.path, subdir, subdir_files_count[subdir.path], &transaction);
if (scan_on_startup_) ScanSubdirectory(subdir.path, subdir, subdir_files_count[subdir.path], &transaction);
if (monitor_) AddWatch(dir, subdir.path);
} }
if (!stop_requested_ && !abort_requested_) {
last_scan_time_ = QDateTime::currentSecsSinceEpoch(); last_scan_time_ = QDateTime::currentSecsSinceEpoch();
}
}
} }
emit CompilationsNeedUpdating(); emit CompilationsNeedUpdating();