command/playlist: save only if at least one song was added
This commit is contained in:
parent
b4e72aba6c
commit
651f57bced
@ -233,10 +233,12 @@ handle_playlistadd_position(Client &client, const char *playlist_name,
|
||||
#ifdef ENABLE_DATABASE
|
||||
const DatabaseSelection selection(uri, true, nullptr);
|
||||
|
||||
SearchInsertIntoPlaylist(client.GetDatabaseOrThrow(),
|
||||
if (SearchInsertIntoPlaylist(client.GetDatabaseOrThrow(),
|
||||
client.GetStorage(),
|
||||
selection,
|
||||
editor, position);
|
||||
editor, position) == 0)
|
||||
/* no song was found, don't need to save */
|
||||
return CommandResult::OK;
|
||||
#else
|
||||
(void)client;
|
||||
r.Error(ACK_ERROR_NO_EXIST, "No database");
|
||||
|
@ -42,7 +42,7 @@ search_add_to_playlist(const Database &db, const Storage *storage,
|
||||
db.Visit(selection, f);
|
||||
}
|
||||
|
||||
void
|
||||
unsigned
|
||||
SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||
const DatabaseSelection &selection,
|
||||
PlaylistFileEditor &playlist,
|
||||
@ -50,9 +50,14 @@ SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||
{
|
||||
assert(position <= playlist.size());
|
||||
|
||||
db.Visit(selection, [&playlist, &position, storage](const auto &song){
|
||||
playlist.Insert(position,
|
||||
unsigned n = 0;
|
||||
|
||||
db.Visit(selection, [&playlist, &position, &n, storage](const auto &song){
|
||||
playlist.Insert(position + n,
|
||||
DatabaseDetachSong(storage, song));
|
||||
++position;
|
||||
++n;
|
||||
});
|
||||
|
||||
return n;
|
||||
}
|
||||
|
@ -33,7 +33,10 @@ search_add_to_playlist(const Database &db, const Storage *storage,
|
||||
const char *playlist_path_utf8,
|
||||
const DatabaseSelection &selection);
|
||||
|
||||
void
|
||||
/**
|
||||
* @return the number of songs added
|
||||
*/
|
||||
unsigned
|
||||
SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||
const DatabaseSelection &selection,
|
||||
PlaylistFileEditor &playlist,
|
||||
|
Loading…
Reference in New Issue
Block a user