Commit bbfa6fe6 authored by Max Kellermann's avatar Max Kellermann

db/simple: purge songs for unavailable decoder plugins on update

parent bf97d13d
ver 0.22.2 (not yet released) ver 0.22.2 (not yet released)
* database * database
- simple: purge virtual directories for unavailable plugins on update - simple: purge songs and virtual directories for unavailable plugins
on update
ver 0.22.1 (2020/10/17) ver 0.22.1 (2020/10/17)
* decoder * decoder
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "db/plugins/simple/Directory.hxx" #include "db/plugins/simple/Directory.hxx"
#include "storage/StorageInterface.hxx" #include "storage/StorageInterface.hxx"
#include "storage/FileInfo.hxx" #include "storage/FileInfo.hxx"
#include "decoder/DecoderList.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "fs/FileInfo.hxx" #include "fs/FileInfo.hxx"
#include "tag/Builder.hxx" #include "tag/Builder.hxx"
...@@ -40,6 +41,14 @@ ...@@ -40,6 +41,14 @@
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
bool
Song::IsPluginAvailable() const noexcept
{
const char *suffix = GetFilenameSuffix();
return suffix != nullptr &&
decoder_plugins_supports_suffix(suffix);
}
SongPtr SongPtr
Song::LoadFile(Storage &storage, const char *path_utf8, Directory &parent) Song::LoadFile(Storage &storage, const char *path_utf8, Directory &parent)
{ {
......
...@@ -34,6 +34,14 @@ Song::Song(DetachedSong &&other, Directory &_parent) noexcept ...@@ -34,6 +34,14 @@ Song::Song(DetachedSong &&other, Directory &_parent) noexcept
{ {
} }
const char *
Song::GetFilenameSuffix() const noexcept
{
return target.empty()
? PathTraitsUTF8::GetFilenameSuffix(filename.c_str())
: PathTraitsUTF8::GetPathSuffix(target.c_str());
}
std::string std::string
Song::GetURI() const noexcept Song::GetURI() const noexcept
{ {
......
...@@ -108,6 +108,16 @@ struct Song { ...@@ -108,6 +108,16 @@ struct Song {
Song(DetachedSong &&other, Directory &_parent) noexcept; Song(DetachedSong &&other, Directory &_parent) noexcept;
gcc_pure
const char *GetFilenameSuffix() const noexcept;
/**
* Checks whether the decoder plugin for this song is
* available.
*/
gcc_pure
bool IsPluginAvailable() const noexcept;
/** /**
* allocate a new song structure with a local file name and attempt to * allocate a new song structure with a local file name and attempt to
* load its metadata. If all decoder plugin fail to read its meta * load its metadata. If all decoder plugin fail to read its meta
......
...@@ -111,7 +111,11 @@ UpdateWalk::PurgeDeletedFromDirectory(Directory &directory) noexcept ...@@ -111,7 +111,11 @@ UpdateWalk::PurgeDeletedFromDirectory(Directory &directory) noexcept
directory.ForEachSongSafe([&](Song &song){ directory.ForEachSongSafe([&](Song &song){
if (!directory_child_is_regular(storage, directory, if (!directory_child_is_regular(storage, directory,
song.filename)) { song.filename) ||
!song.IsPluginAvailable()) {
/* the song file was deleted (or the decoder
plugin is unavailable) */
editor.LockDeleteSong(directory, &song); editor.LockDeleteSong(directory, &song);
modified = true; modified = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment