Commit d4f3dd49 authored by datasone's avatar datasone Committed by Max Kellermann

db/SimpleDatabasePlugin: store `in_playlist` value of songs into database

Fixes hide_playlist_targets not working after server restart Currently, `hide_playlists_targets` works by skipping songs with `in_playlist` value set to true in [`Directory::Walk`](https://github.com/MusicPlayerDaemon/MPD/blob/a57bcd02382947abbd961594cdf00302c0c7866a/src/db/plugins/simple/Directory.cxx#L237). But `in_playlist` is not stored and only updated in [`UpdateWalk::PurgeDanglingFromPlaylists`](https://github.com/MusicPlayerDaemon/MPD/blob/a57bcd02382947abbd961594cdf00302c0c7866a/src/db/update/Playlist.cxx#L139), which will only be executed while updating DB. This causes the problem that playlist target songs are correctly hidden after database update, but will remain visible after mpd server restarted. This pr solves the problem by storing `in_playlist` value of songs into the `SimpleDatabase` file.
parent 4ec6d055
...@@ -63,6 +63,9 @@ song_save(BufferedOutputStream &os, const Song &song) ...@@ -63,6 +63,9 @@ song_save(BufferedOutputStream &os, const Song &song)
if (song.audio_format.IsDefined()) if (song.audio_format.IsDefined())
os.Format("Format: %s\n", ToString(song.audio_format).c_str()); os.Format("Format: %s\n", ToString(song.audio_format).c_str());
if (song.in_playlist)
os.Write("InPlaylist: yes\n");
if (!IsNegative(song.mtime)) if (!IsNegative(song.mtime))
os.Format(SONG_MTIME ": %li\n", os.Format(SONG_MTIME ": %li\n",
(long)std::chrono::system_clock::to_time_t(song.mtime)); (long)std::chrono::system_clock::to_time_t(song.mtime));
...@@ -86,7 +89,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song) ...@@ -86,7 +89,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song)
DetachedSong DetachedSong
song_load(LineReader &file, const char *uri, song_load(LineReader &file, const char *uri,
std::string *target_r) std::string *target_r, bool *in_playlist_r)
{ {
DetachedSong song(uri); DetachedSong song(uri);
...@@ -132,6 +135,9 @@ song_load(LineReader &file, const char *uri, ...@@ -132,6 +135,9 @@ song_load(LineReader &file, const char *uri,
song.SetStartTime(SongTime::FromMS(start_ms)); song.SetStartTime(SongTime::FromMS(start_ms));
song.SetEndTime(SongTime::FromMS(end_ms)); song.SetEndTime(SongTime::FromMS(end_ms));
} else if (StringIsEqual(line, "InPlaylist")) {
if (in_playlist_r != nullptr)
*in_playlist_r = StringIsEqual(value, "yes");
} else { } else {
throw FormatRuntimeError("unknown line in db: %s", line); throw FormatRuntimeError("unknown line in db: %s", line);
} }
......
...@@ -44,6 +44,6 @@ song_save(BufferedOutputStream &os, const DetachedSong &song); ...@@ -44,6 +44,6 @@ song_save(BufferedOutputStream &os, const DetachedSong &song);
*/ */
DetachedSong DetachedSong
song_load(LineReader &file, const char *uri, song_load(LineReader &file, const char *uri,
std::string *target_r=nullptr); std::string *target_r=nullptr, bool *in_playlist_r=nullptr);
#endif #endif
...@@ -168,12 +168,14 @@ directory_load(LineReader &file, Directory &directory) ...@@ -168,12 +168,14 @@ directory_load(LineReader &file, Directory &directory)
throw FormatRuntimeError("Duplicate song '%s'", name); throw FormatRuntimeError("Duplicate song '%s'", name);
std::string target; std::string target;
bool in_playlist = false;
auto detached_song = song_load(file, name, auto detached_song = song_load(file, name,
&target); &target, &in_playlist);
auto song = std::make_unique<Song>(std::move(detached_song), auto song = std::make_unique<Song>(std::move(detached_song),
directory); directory);
song->target = std::move(target); song->target = std::move(target);
song->in_playlist = in_playlist;
directory.AddSong(std::move(song)); directory.AddSong(std::move(song));
} else if ((p = StringAfterPrefix(line, PLAYLIST_META_BEGIN))) { } else if ((p = StringAfterPrefix(line, PLAYLIST_META_BEGIN))) {
......
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