From 1b8c94d6b999334f5e80651675d5d7b492272ca7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 14 Oct 2021 11:35:35 +0200 Subject: [PATCH] db/update/Playlist: move code to another UpdatePlaylistFile() method --- src/db/update/Playlist.cxx | 70 +++++++++++++++++++++----------------- src/db/update/Walk.hxx | 4 +++ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/db/update/Playlist.cxx b/src/db/update/Playlist.cxx index f783b329f..d6d08afe3 100644 --- a/src/db/update/Playlist.cxx +++ b/src/db/update/Playlist.cxx @@ -35,7 +35,43 @@ #include "util/StringFormat.hxx" #include "Log.hxx" -void +inline void +UpdateWalk::UpdatePlaylistFile(Directory &directory, + SongEnumerator &contents) noexcept +{ + unsigned track = 0; + + while (true) { + auto song = contents.NextSong(); + if (!song) + break; + + auto db_song = std::make_unique(std::move(*song), + directory); + const bool is_absolute = + PathTraitsUTF8::IsAbsoluteOrHasScheme(db_song->filename.c_str()); + db_song->target = is_absolute + ? db_song->filename + /* prepend "../" to relative paths to go from + the virtual directory (DEVICE_PLAYLIST) to + the containing directory */ + : "../" + db_song->filename; + db_song->filename = StringFormat<64>("track%04u", + ++track); + + { + const ScopeDatabaseLock protect; + + if (!is_absolute && + !directory.TargetExists(db_song->target)) + continue; + + directory.AddSong(std::move(db_song)); + } + } +} + +inline void UpdateWalk::UpdatePlaylistFile(Directory &parent, std::string_view name, const StorageFileInfo &info, const PlaylistPlugin &plugin) noexcept @@ -63,37 +99,7 @@ UpdateWalk::UpdatePlaylistFile(Directory &parent, std::string_view name, return; } - unsigned track = 0; - - while (true) { - auto song = e->NextSong(); - if (!song) - break; - - auto db_song = std::make_unique(std::move(*song), - *directory); - const bool is_absolute = - PathTraitsUTF8::IsAbsoluteOrHasScheme(db_song->filename.c_str()); - db_song->target = is_absolute - ? db_song->filename - /* prepend "../" to relative paths to - go from the virtual directory - (DEVICE_PLAYLIST) to the containing - directory */ - : "../" + db_song->filename; - db_song->filename = StringFormat<64>("track%04u", - ++track); - - { - const ScopeDatabaseLock protect; - - if (!is_absolute && - !directory->TargetExists(db_song->target)) - continue; - - directory->AddSong(std::move(db_song)); - } - } + UpdatePlaylistFile(*directory, *e); if (directory->IsEmpty()) editor.LockDeleteDirectory(directory); diff --git a/src/db/update/Walk.hxx b/src/db/update/Walk.hxx index c777751f1..29295d1bf 100644 --- a/src/db/update/Walk.hxx +++ b/src/db/update/Walk.hxx @@ -31,6 +31,7 @@ struct StorageFileInfo; struct Directory; struct ArchivePlugin; struct PlaylistPlugin; +class SongEnumerator; class ArchiveFile; class Storage; class ExcludeList; @@ -125,6 +126,9 @@ private: } #endif + void UpdatePlaylistFile(Directory &directory, + SongEnumerator &contents) noexcept; + void UpdatePlaylistFile(Directory &parent, std::string_view name, const StorageFileInfo &info, const PlaylistPlugin &plugin) noexcept;