summaryrefslogtreecommitdiff
path: root/src/PlaylistSave.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-03-24 20:37:44 +0100
committerMax Kellermann <max@duempel.org>2015-03-24 22:03:17 +0100
commitf9e0f0d25700c0674763def6134e18ef8a6a9da4 (patch)
treef4173a1ee624e9c7b1d78375fada4511c47cf632 /src/PlaylistSave.cxx
parent98f3135ad347fb39f941d03f5b8cadc6bc23f658 (diff)
PlaylistSave: return bool/Error instead of PlaylistResult
Diffstat (limited to 'src/PlaylistSave.cxx')
-rw-r--r--src/PlaylistSave.cxx37
1 files changed, 19 insertions, 18 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);
}