diff options
author | Max Kellermann <max@duempel.org> | 2015-03-24 20:37:44 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-03-24 22:03:17 +0100 |
commit | f9e0f0d25700c0674763def6134e18ef8a6a9da4 (patch) | |
tree | f4173a1ee624e9c7b1d78375fada4511c47cf632 /src | |
parent | 98f3135ad347fb39f941d03f5b8cadc6bc23f658 (diff) | |
download | mpd-f9e0f0d25700c0674763def6134e18ef8a6a9da4.tar.gz mpd-f9e0f0d25700c0674763def6134e18ef8a6a9da4.tar.xz mpd-f9e0f0d25700c0674763def6134e18ef8a6a9da4.zip |
PlaylistSave: return bool/Error instead of PlaylistResult
Diffstat (limited to 'src')
-rw-r--r-- | src/PlaylistSave.cxx | 37 | ||||
-rw-r--r-- | src/PlaylistSave.hxx | 9 | ||||
-rw-r--r-- | src/command/PlaylistCommands.cxx | 6 |
3 files changed, 28 insertions, 24 deletions
diff --git a/src/PlaylistSave.cxx b/src/PlaylistSave.cxx index c4c3a8ecd..61b4913b2 100644 --- a/src/PlaylistSave.cxx +++ b/src/PlaylistSave.cxx @@ -65,26 +65,26 @@ playlist_print_uri(FILE *file, const char *uri) fprintf(file, "%s\n", NarrowPath(path).c_str()); } -PlaylistResult -spl_save_queue(const char *name_utf8, const Queue &queue) +bool +spl_save_queue(const char *name_utf8, const Queue &queue, Error &error) { - if (map_spl_path().IsNull()) - return PlaylistResult::DISABLED; - - if (!spl_valid_name(name_utf8)) - return PlaylistResult::BAD_NAME; - - const auto path_fs = map_spl_utf8_to_fs(name_utf8); + const auto path_fs = spl_map_to_fs(name_utf8, error); if (path_fs.IsNull()) - return PlaylistResult::BAD_NAME; + return false; - if (FileExists(path_fs)) - return PlaylistResult::LIST_EXISTS; + if (FileExists(path_fs)) { + error.Set(playlist_domain, int(PlaylistResult::LIST_EXISTS), + "Playlist already exists"); + return false; + } FILE *file = FOpen(path_fs, FOpenMode::WriteText); - if (file == nullptr) - return PlaylistResult::ERRNO; + if (file == nullptr) { + error.FormatErrno("Failed to open %s", + path_fs.ToUTF8().c_str()); + return false; + } for (unsigned i = 0; i < queue.GetLength(); i++) playlist_print_song(file, queue.Get(i)); @@ -92,11 +92,12 @@ spl_save_queue(const char *name_utf8, const Queue &queue) fclose(file); idle_add(IDLE_STORED_PLAYLIST); - return PlaylistResult::SUCCESS; + return true; } -PlaylistResult -spl_save_playlist(const char *name_utf8, const playlist &playlist) +bool +spl_save_playlist(const char *name_utf8, const playlist &playlist, + Error &error) { - return spl_save_queue(name_utf8, playlist.queue); + return spl_save_queue(name_utf8, playlist.queue, error); } diff --git a/src/PlaylistSave.hxx b/src/PlaylistSave.hxx index 5b2a84dfb..35b88efc6 100644 --- a/src/PlaylistSave.hxx +++ b/src/PlaylistSave.hxx @@ -39,13 +39,14 @@ playlist_print_uri(FILE *fp, const char *uri); /** * Saves a queue object into a stored playlist file. */ -PlaylistResult -spl_save_queue(const char *name_utf8, const Queue &queue); +bool +spl_save_queue(const char *name_utf8, const Queue &queue, Error &error); /** * Saves a playlist object into a stored playlist file. */ -PlaylistResult -spl_save_playlist(const char *name_utf8, const playlist &playlist); +bool +spl_save_playlist(const char *name_utf8, const playlist &playlist, + Error &error); #endif diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx index 9d870b021..516726500 100644 --- a/src/command/PlaylistCommands.cxx +++ b/src/command/PlaylistCommands.cxx @@ -61,8 +61,10 @@ print_spl_list(Client &client, const PlaylistVector &list) CommandResult handle_save(Client &client, ConstBuffer<const char *> args) { - PlaylistResult result = spl_save_playlist(args.front(), client.playlist); - return print_playlist_result(client, result); + Error error; + return spl_save_playlist(args.front(), client.playlist, error) + ? CommandResult::OK + : print_error(client, error); } CommandResult |