db/simple: prune CUE entries from database for non-existent songs
Closes https://github.com/MusicPlayerDaemon/MPD/issues/1019
This commit is contained in:
@@ -133,6 +133,28 @@ UpdateWalk::PurgeDeletedFromDirectory(Directory &directory) noexcept
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UpdateWalk::PurgeDanglingFromPlaylists(Directory &directory) noexcept
|
||||
{
|
||||
/* recurse */
|
||||
for (Directory &child : directory.children)
|
||||
PurgeDanglingFromPlaylists(child);
|
||||
|
||||
if (!directory.IsPlaylist())
|
||||
/* this check is only for virtual directories
|
||||
representing a playlist file */
|
||||
return;
|
||||
|
||||
directory.ForEachSongSafe([&](Song &song){
|
||||
if (!song.target.empty() &&
|
||||
!PathTraitsUTF8::IsAbsoluteOrHasScheme(song.target.c_str()) &&
|
||||
!directory.TargetExists(song.target)) {
|
||||
editor.DeleteSong(directory, &song);
|
||||
modified = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
static bool
|
||||
update_directory_stat(Storage &storage, Directory &directory) noexcept
|
||||
@@ -530,5 +552,10 @@ UpdateWalk::Walk(Directory &root, const char *path, bool discard) noexcept
|
||||
UpdateDirectory(root, exclude_list, info);
|
||||
}
|
||||
|
||||
{
|
||||
const ScopeDatabaseLock protect;
|
||||
PurgeDanglingFromPlaylists(root);
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
@@ -85,6 +85,12 @@ private:
|
||||
|
||||
void PurgeDeletedFromDirectory(Directory &directory) noexcept;
|
||||
|
||||
/**
|
||||
* Remove all virtual songs inside playlists whose "target"
|
||||
* field points to a non-existing song file.
|
||||
*/
|
||||
void PurgeDanglingFromPlaylists(Directory &directory) noexcept;
|
||||
|
||||
void UpdateSongFile2(Directory &directory,
|
||||
const char *name, const char *suffix,
|
||||
const StorageFileInfo &info) noexcept;
|
||||
|
||||
Reference in New Issue
Block a user