aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/PlaylistSave.cxx37
-rw-r--r--src/PlaylistSave.hxx9
-rw-r--r--src/command/PlaylistCommands.cxx6
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