1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-22 07:54:18 +01:00

library: Fix rescan in case where library directory was recreated

If a root library directory is deleted and recreated, it is not
detected since inotify would need to watch the parent directory. On
rescan, if the subdirectory list for a directory is empty, re-add the
library's root directory.

This is an edge case on Linux systems. The issue may not exist on other
operating systems.
This commit is contained in:
Jim Broadus 2021-03-29 00:14:46 -07:00 committed by John Maguire
parent fd3a2a2f12
commit f4e70face1

View File

@ -230,6 +230,7 @@ void LibraryWatcher::WatchList::Add(const Directory& dir) {
void LibraryWatcher::AddDirectory(const Directory& dir,
const SubdirectoryList& subdirs) {
qLog(Debug) << "Add directory" << dir.GetPath();
watched_dirs_.Add(dir);
const WatchedDir& new_dir = watched_dirs_.list_[dir.id];
@ -878,8 +879,21 @@ void LibraryWatcher::FullScanNow() { PerformScan(false, true); }
void LibraryWatcher::PerformScan(bool incremental, bool ignore_mtimes) {
for (const WatchedDir& dir : watched_dirs_.list_.values()) {
qLog(Debug) << "Scanning library directory" << dir.GetPath();
ScanTransaction transaction(this, dir, incremental, ignore_mtimes);
SubdirectoryList subdirs(transaction.GetAllSubdirs());
// On Linux systems, if the library directory is deleted then re-created,
// inotify won't find it. This could be corrected by watching parent
// directories, but not worth the complexity for an edge case.
if (subdirs.isEmpty()) {
qLog(Debug) << "Library directory wasn't in subdir list.";
Subdirectory subdir;
subdir.path = dir.GetPath();
subdir.directory_id = dir.GetId();
subdirs << subdir;
}
transaction.AddToProgressMax(subdirs.count());
for (const Subdirectory& subdir : subdirs) {