Commit a8b225f9 authored by Max Kellermann's avatar Max Kellermann

playlist: don't pass "fd" to storedPlaylist.c functions

Return an "enum playlist_result" value instead of calling commandError() in storedPlaylist.c.
parent 8d2830b3
...@@ -531,7 +531,10 @@ static int handleSave(int fd, mpd_unused int *permission, ...@@ -531,7 +531,10 @@ static int handleSave(int fd, mpd_unused int *permission,
static int handleLoad(int fd, mpd_unused int *permission, static int handleLoad(int fd, mpd_unused int *permission,
mpd_unused int argc, char *argv[]) mpd_unused int argc, char *argv[])
{ {
return loadPlaylist(fd, argv[1]); enum playlist_result result;
result = loadPlaylist(fd, argv[1]);
return print_playlist_result(fd, result);
} }
static int handleListPlaylist(int fd, mpd_unused int *permission, static int handleListPlaylist(int fd, mpd_unused int *permission,
...@@ -575,7 +578,10 @@ static int handleRm(int fd, mpd_unused int *permission, ...@@ -575,7 +578,10 @@ static int handleRm(int fd, mpd_unused int *permission,
static int handleRename(int fd, mpd_unused int *permission, static int handleRename(int fd, mpd_unused int *permission,
mpd_unused int argc, char *argv[]) mpd_unused int argc, char *argv[])
{ {
return renameStoredPlaylist(fd, argv[1], argv[2]); enum playlist_result result;
result = renameStoredPlaylist(argv[1], argv[2]);
return print_playlist_result(fd, result);
} }
static int handlePlaylistChanges(int fd, mpd_unused int *permission, static int handlePlaylistChanges(int fd, mpd_unused int *permission,
...@@ -734,11 +740,13 @@ static int handlePlaylistDelete(int fd, mpd_unused int *permission, ...@@ -734,11 +740,13 @@ static int handlePlaylistDelete(int fd, mpd_unused int *permission,
mpd_unused int argc, char *argv[]) { mpd_unused int argc, char *argv[]) {
char *playlist = argv[1]; char *playlist = argv[1];
int from; int from;
enum playlist_result result;
if (check_int(fd, &from, argv[2], check_integer, argv[2]) < 0) if (check_int(fd, &from, argv[2], check_integer, argv[2]) < 0)
return -1; return -1;
return removeOneSongFromStoredPlaylistByPath(fd, playlist, from); result = removeOneSongFromStoredPlaylistByPath(playlist, from);
return print_playlist_result(fd, result);
} }
static int handlePlaylistMove(int fd, mpd_unused int *permission, static int handlePlaylistMove(int fd, mpd_unused int *permission,
...@@ -746,13 +754,15 @@ static int handlePlaylistMove(int fd, mpd_unused int *permission, ...@@ -746,13 +754,15 @@ static int handlePlaylistMove(int fd, mpd_unused int *permission,
{ {
char *playlist = argv[1]; char *playlist = argv[1];
int from, to; int from, to;
enum playlist_result result;
if (check_int(fd, &from, argv[2], check_integer, argv[2]) < 0) if (check_int(fd, &from, argv[2], check_integer, argv[2]) < 0)
return -1; return -1;
if (check_int(fd, &to, argv[3], check_integer, argv[3]) < 0) if (check_int(fd, &to, argv[3], check_integer, argv[3]) < 0)
return -1; return -1;
return moveSongInStoredPlaylistByPath(fd, playlist, from, to); result = moveSongInStoredPlaylistByPath(playlist, from, to);
return print_playlist_result(fd, result);
} }
static int listHandleUpdate(int fd, static int listHandleUpdate(int fd,
...@@ -1137,7 +1147,10 @@ static int handleNotcommands(int fd, mpd_unused int *permission, ...@@ -1137,7 +1147,10 @@ static int handleNotcommands(int fd, mpd_unused int *permission,
static int handlePlaylistClear(int fd, mpd_unused int *permission, static int handlePlaylistClear(int fd, mpd_unused int *permission,
mpd_unused int argc, char *argv[]) mpd_unused int argc, char *argv[])
{ {
return clearStoredPlaylist(fd, argv[1]); enum playlist_result result;
result = clearStoredPlaylist(argv[1]);
return print_playlist_result(fd, result);
} }
static int handlePlaylistAdd(int fd, mpd_unused int *permission, static int handlePlaylistAdd(int fd, mpd_unused int *permission,
...@@ -1145,11 +1158,13 @@ static int handlePlaylistAdd(int fd, mpd_unused int *permission, ...@@ -1145,11 +1158,13 @@ static int handlePlaylistAdd(int fd, mpd_unused int *permission,
{ {
char *playlist = argv[1]; char *playlist = argv[1];
char *path = argv[2]; char *path = argv[2];
enum playlist_result result;
if (isRemoteUrl(path)) if (isRemoteUrl(path))
return addToStoredPlaylist(fd, path, playlist); result = addToStoredPlaylist(path, playlist);
else
return addAllInToStoredPlaylist(fd, path, playlist); result = addAllInToStoredPlaylist(fd, path, playlist);
return print_playlist_result(fd, result);
} }
void initCommands(void) void initCommands(void)
......
...@@ -180,11 +180,10 @@ static int directoryAddSongToPlaylist(mpd_unused int fd, Song * song, ...@@ -180,11 +180,10 @@ static int directoryAddSongToPlaylist(mpd_unused int fd, Song * song,
return addSongToPlaylist(song, NULL); return addSongToPlaylist(song, NULL);
} }
static int directoryAddSongToStoredPlaylist(int fd, Song *song, void *data) static int directoryAddSongToStoredPlaylist(mpd_unused int fd, Song *song,
void *data)
{ {
if (appendSongToStoredPlaylistByPath(fd, (char *)data, song) != 0) return appendSongToStoredPlaylistByPath((char *)data, song);
return -1;
return 0;
} }
int addAllIn(int fd, const char *name) int addAllIn(int fd, const char *name)
......
...@@ -212,9 +212,9 @@ void clearPlaylist(void) ...@@ -212,9 +212,9 @@ void clearPlaylist(void)
incrPlaylistVersion(); incrPlaylistVersion();
} }
int clearStoredPlaylist(int fd, const char *utf8file) int clearStoredPlaylist(const char *utf8file)
{ {
return removeAllFromStoredPlaylistByPath(fd, utf8file); return removeAllFromStoredPlaylistByPath(utf8file);
} }
void showPlaylist(int fd) void showPlaylist(int fd)
...@@ -568,32 +568,27 @@ enum playlist_result addToPlaylist(const char *url, int *added_id) ...@@ -568,32 +568,27 @@ enum playlist_result addToPlaylist(const char *url, int *added_id)
return addSongToPlaylist(song, added_id); return addSongToPlaylist(song, added_id);
} }
int addToStoredPlaylist(int fd, const char *url, const char *utf8file) int addToStoredPlaylist(const char *url, const char *utf8file)
{ {
Song *song; Song *song;
DEBUG("add to stored playlist: %s\n", url); DEBUG("add to stored playlist: %s\n", url);
song = getSongFromDB(url); song = getSongFromDB(url);
if (song) { if (song)
appendSongToStoredPlaylistByPath(fd, utf8file, song); return appendSongToStoredPlaylistByPath(utf8file, song);
return 0;
}
if (!isValidRemoteUtf8Url(url)) if (!isValidRemoteUtf8Url(url))
goto fail; return ACK_ERROR_NO_EXIST;
song = newSong(url, SONG_TYPE_URL, NULL); song = newSong(url, SONG_TYPE_URL, NULL);
if (song) { if (song) {
appendSongToStoredPlaylistByPath(fd, utf8file, song); int ret = appendSongToStoredPlaylistByPath(utf8file, song);
freeJustSong(song); freeJustSong(song);
return 0; return ret;
} }
fail: return ACK_ERROR_NO_EXIST;
commandError(fd, ACK_ERROR_NO_EXIST, "\"%s\" is not in the music db"
"or is not a valid url", url);
return -1;
} }
enum playlist_result addSongToPlaylist(Song * song, int *added_id) enum playlist_result addSongToPlaylist(Song * song, int *added_id)
...@@ -1347,8 +1342,11 @@ int PlaylistInfo(int fd, const char *utf8file, int detail) ...@@ -1347,8 +1342,11 @@ int PlaylistInfo(int fd, const char *utf8file, int detail)
ListNode *node; ListNode *node;
List *list; List *list;
if (!(list = loadStoredPlaylist(fd, utf8file))) if (!(list = loadStoredPlaylist(utf8file))) {
commandError(fd, ACK_ERROR_NO_EXIST, "could not open playlist "
"\"%s\": %s", utf8file, strerror(errno));
return -1; return -1;
}
node = list->firstNode; node = list->firstNode;
while (node != NULL) { while (node != NULL) {
...@@ -1374,13 +1372,13 @@ int PlaylistInfo(int fd, const char *utf8file, int detail) ...@@ -1374,13 +1372,13 @@ int PlaylistInfo(int fd, const char *utf8file, int detail)
return 0; return 0;
} }
int loadPlaylist(int fd, const char *utf8file) enum playlist_result loadPlaylist(int fd, const char *utf8file)
{ {
ListNode *node; ListNode *node;
List *list; List *list;
if (!(list = loadStoredPlaylist(fd, utf8file))) if (!(list = loadStoredPlaylist(utf8file)))
return -1; return PLAYLIST_RESULT_NO_SUCH_LIST;
node = list->firstNode; node = list->firstNode;
while (node != NULL) { while (node != NULL) {
...@@ -1405,7 +1403,7 @@ int loadPlaylist(int fd, const char *utf8file) ...@@ -1405,7 +1403,7 @@ int loadPlaylist(int fd, const char *utf8file)
} }
freeList(list); freeList(list);
return 0; return PLAYLIST_RESULT_SUCCESS;
} }
void searchForSongsInPlaylist(int fd, int numItems, LocateTagItem * items) void searchForSongsInPlaylist(int fd, int numItems, LocateTagItem * items)
...@@ -1456,17 +1454,3 @@ int is_valid_playlist_name(const char *utf8path) ...@@ -1456,17 +1454,3 @@ int is_valid_playlist_name(const char *utf8path)
strchr(utf8path, '\n') == NULL && strchr(utf8path, '\n') == NULL &&
strchr(utf8path, '\r') == NULL; strchr(utf8path, '\r') == NULL;
} }
int valid_playlist_name(int err_fd, const char *utf8path)
{
if (!is_valid_playlist_name(utf8path)) {
commandError(err_fd, ACK_ERROR_ARG, "playlist name \"%s\" is "
"invalid: playlist names may not contain slashes,"
" newlines or carriage returns",
utf8path);
return 0;
}
return 1;
}
...@@ -65,11 +65,11 @@ void savePlaylistState(FILE *); ...@@ -65,11 +65,11 @@ void savePlaylistState(FILE *);
void clearPlaylist(void); void clearPlaylist(void);
int clearStoredPlaylist(int fd, const char *utf8file); int clearStoredPlaylist(const char *utf8file);
enum playlist_result addToPlaylist(const char *file, int *added_id); enum playlist_result addToPlaylist(const char *file, int *added_id);
int addToStoredPlaylist(int fd, const char *file, const char *utf8file); int addToStoredPlaylist(const char *file, const char *utf8file);
enum playlist_result addSongToPlaylist(Song * song, int *added_id); enum playlist_result addSongToPlaylist(Song * song, int *added_id);
...@@ -111,7 +111,7 @@ enum playlist_result swapSongsInPlaylist(int song1, int song2); ...@@ -111,7 +111,7 @@ enum playlist_result swapSongsInPlaylist(int song1, int song2);
enum playlist_result swapSongsInPlaylistById(int id1, int id2); enum playlist_result swapSongsInPlaylistById(int id1, int id2);
int loadPlaylist(int fd, const char *utf8file); enum playlist_result loadPlaylist(int fd, const char *utf8file);
int getPlaylistRepeatStatus(void); int getPlaylistRepeatStatus(void);
...@@ -149,6 +149,4 @@ void findSongsInPlaylist(int fd, int numItems, LocateTagItem * items); ...@@ -149,6 +149,4 @@ void findSongsInPlaylist(int fd, int numItems, LocateTagItem * items);
int is_valid_playlist_name(const char *utf8path); int is_valid_playlist_name(const char *utf8path);
int valid_playlist_name(int err_fd, const char *utf8path);
#endif #endif
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
#include "storedPlaylist.h" #include "storedPlaylist.h"
#include "path.h" #include "path.h"
#include "utils.h" #include "utils.h"
#include "ack.h"
#include "command.h"
#include "ls.h" #include "ls.h"
#include "directory.h" #include "directory.h"
#include "os_compat.h" #include "os_compat.h"
...@@ -60,7 +58,8 @@ static ListNode *nodeOfStoredPlaylist(List *list, int idx) ...@@ -60,7 +58,8 @@ static ListNode *nodeOfStoredPlaylist(List *list, int idx)
return NULL; return NULL;
} }
static int writeStoredPlaylistToPath(int fd, List *list, const char *fspath) static enum playlist_result
writeStoredPlaylistToPath(List *list, const char *fspath)
{ {
ListNode *node; ListNode *node;
FILE *file; FILE *file;
...@@ -69,11 +68,8 @@ static int writeStoredPlaylistToPath(int fd, List *list, const char *fspath) ...@@ -69,11 +68,8 @@ static int writeStoredPlaylistToPath(int fd, List *list, const char *fspath)
assert(fspath != NULL); assert(fspath != NULL);
while (!(file = fopen(fspath, "w")) && errno == EINTR); while (!(file = fopen(fspath, "w")) && errno == EINTR);
if (file == NULL) { if (file == NULL)
commandError(fd, ACK_ERROR_NO_EXIST, "could not open file " return PLAYLIST_RESULT_ERRNO;
"\"%s\": %s", fspath, strerror(errno));
return -1;
}
node = list->firstNode; node = list->firstNode;
while (node != NULL) { while (node != NULL) {
...@@ -87,10 +83,10 @@ static int writeStoredPlaylistToPath(int fd, List *list, const char *fspath) ...@@ -87,10 +83,10 @@ static int writeStoredPlaylistToPath(int fd, List *list, const char *fspath)
} }
while (fclose(file) != 0 && errno == EINTR); while (fclose(file) != 0 && errno == EINTR);
return 0; return PLAYLIST_RESULT_SUCCESS;
} }
List *loadStoredPlaylist(int fd, const char *utf8path) List *loadStoredPlaylist(const char *utf8path)
{ {
List *list; List *list;
FILE *file; FILE *file;
...@@ -98,16 +94,13 @@ List *loadStoredPlaylist(int fd, const char *utf8path) ...@@ -98,16 +94,13 @@ List *loadStoredPlaylist(int fd, const char *utf8path)
char path_max_tmp[MPD_PATH_MAX]; char path_max_tmp[MPD_PATH_MAX];
const size_t musicDir_len = strlen(musicDir); const size_t musicDir_len = strlen(musicDir);
if (!valid_playlist_name(fd, utf8path)) if (!is_valid_playlist_name(utf8path))
return NULL; return NULL;
utf8_to_fs_playlist_path(path_max_tmp, utf8path); utf8_to_fs_playlist_path(path_max_tmp, utf8path);
while (!(file = fopen(path_max_tmp, "r")) && errno == EINTR); while (!(file = fopen(path_max_tmp, "r")) && errno == EINTR);
if (file == NULL) { if (file == NULL)
commandError(fd, ACK_ERROR_NO_EXIST, "could not open file "
"\"%s\": %s", path_max_tmp, strerror(errno));
return NULL; return NULL;
}
list = makeList(DEFAULT_FREE_DATA_FUNC, 0); list = makeList(DEFAULT_FREE_DATA_FUNC, 0);
...@@ -135,15 +128,13 @@ List *loadStoredPlaylist(int fd, const char *utf8path) ...@@ -135,15 +128,13 @@ List *loadStoredPlaylist(int fd, const char *utf8path)
return list; return list;
} }
static int moveSongInStoredPlaylist(int fd, List *list, int src, int dest) static int moveSongInStoredPlaylist(List *list, int src, int dest)
{ {
ListNode *srcNode, *destNode; ListNode *srcNode, *destNode;
if (src >= list->numberOfNodes || dest >= list->numberOfNodes || if (src >= list->numberOfNodes || dest >= list->numberOfNodes ||
src < 0 || dest < 0 || src == dest) { src < 0 || dest < 0 || src == dest)
commandError(fd, ACK_ERROR_ARG, "argument out of range");
return -1; return -1;
}
srcNode = nodeOfStoredPlaylist(list, src); srcNode = nodeOfStoredPlaylist(list, src);
if (!srcNode) if (!srcNode)
...@@ -197,90 +188,78 @@ static int moveSongInStoredPlaylist(int fd, List *list, int src, int dest) ...@@ -197,90 +188,78 @@ static int moveSongInStoredPlaylist(int fd, List *list, int src, int dest)
return 0; return 0;
} }
int moveSongInStoredPlaylistByPath(int fd, const char *utf8path, enum playlist_result
int src, int dest) moveSongInStoredPlaylistByPath(const char *utf8path, int src, int dest)
{ {
List *list; List *list;
enum playlist_result result;
if (!(list = loadStoredPlaylist(fd, utf8path))) { if (!(list = loadStoredPlaylist(utf8path)))
commandError(fd, ACK_ERROR_UNKNOWN, "could not open playlist"); return PLAYLIST_RESULT_NO_SUCH_LIST;
return -1;
}
if (moveSongInStoredPlaylist(fd, list, src, dest) != 0) { if (moveSongInStoredPlaylist(list, src, dest) != 0) {
freeList(list); freeList(list);
return -1; return PLAYLIST_RESULT_BAD_RANGE;
} }
if (writeStoredPlaylistToPath(fd, list, utf8path) != 0) { result = writeStoredPlaylistToPath(list, utf8path);
commandError(fd, ACK_ERROR_UNKNOWN, "failed to save playlist");
freeList(list);
return -1;
}
freeList(list); freeList(list);
return 0; return result;
} }
int removeAllFromStoredPlaylistByPath(int fd, const char *utf8path) enum playlist_result
removeAllFromStoredPlaylistByPath(const char *utf8path)
{ {
char filename[MPD_PATH_MAX]; char filename[MPD_PATH_MAX];
FILE *file; FILE *file;
if (!valid_playlist_name(fd, utf8path)) if (!is_valid_playlist_name(utf8path))
return -1; return PLAYLIST_RESULT_BAD_NAME;
utf8_to_fs_playlist_path(filename, utf8path); utf8_to_fs_playlist_path(filename, utf8path);
while (!(file = fopen(filename, "w")) && errno == EINTR); while (!(file = fopen(filename, "w")) && errno == EINTR);
if (file == NULL) { if (file == NULL)
commandError(fd, ACK_ERROR_NO_EXIST, "could not open file " return PLAYLIST_RESULT_ERRNO;
"\"%s\": %s", filename, strerror(errno));
return -1;
}
while (fclose(file) != 0 && errno == EINTR); while (fclose(file) != 0 && errno == EINTR);
return 0; return PLAYLIST_RESULT_SUCCESS;
} }
static int removeOneSongFromStoredPlaylist(int fd, List *list, int pos) static int removeOneSongFromStoredPlaylist(List *list, int pos)
{ {
ListNode *node = nodeOfStoredPlaylist(list, pos); ListNode *node = nodeOfStoredPlaylist(list, pos);
if (!node) { if (!node)
commandError(fd, ACK_ERROR_ARG,
"could not find song at position");
return -1; return -1;
}
deleteNodeFromList(list, node); deleteNodeFromList(list, node);
return 0; return 0;
} }
int removeOneSongFromStoredPlaylistByPath(int fd, const char *utf8path, int pos) enum playlist_result
removeOneSongFromStoredPlaylistByPath(const char *utf8path, int pos)
{ {
List *list; List *list;
enum playlist_result result;
if (!(list = loadStoredPlaylist(fd, utf8path))) { if (!(list = loadStoredPlaylist(utf8path)))
commandError(fd, ACK_ERROR_UNKNOWN, "could not open playlist"); return PLAYLIST_RESULT_NO_SUCH_LIST;
return -1;
}
if (removeOneSongFromStoredPlaylist(fd, list, pos) != 0) { if (removeOneSongFromStoredPlaylist(list, pos) != 0) {
freeList(list); freeList(list);
return -1; return PLAYLIST_RESULT_BAD_RANGE;
} }
if (writeStoredPlaylistToPath(fd, list, utf8path) != 0) { result = writeStoredPlaylistToPath(list, utf8path);
commandError(fd, ACK_ERROR_UNKNOWN, "failed to save playlist");
freeList(list);
return -1;
}
freeList(list); freeList(list);
return 0; return result;
} }
int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song) enum playlist_result
appendSongToStoredPlaylistByPath(const char *utf8path, Song *song)
{ {
FILE *file; FILE *file;
char *s; char *s;
...@@ -288,27 +267,28 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song) ...@@ -288,27 +267,28 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song)
char path_max_tmp[MPD_PATH_MAX]; char path_max_tmp[MPD_PATH_MAX];
char path_max_tmp2[MPD_PATH_MAX]; char path_max_tmp2[MPD_PATH_MAX];
if (!valid_playlist_name(fd, utf8path)) if (!is_valid_playlist_name(utf8path))
return -1; return PLAYLIST_RESULT_BAD_NAME;
utf8_to_fs_playlist_path(path_max_tmp, utf8path); utf8_to_fs_playlist_path(path_max_tmp, utf8path);
while (!(file = fopen(path_max_tmp, "a")) && errno == EINTR); while (!(file = fopen(path_max_tmp, "a")) && errno == EINTR);
if (file == NULL) { if (file == NULL) {
commandError(fd, ACK_ERROR_NO_EXIST, "could not open file " int save_errno = errno;
"\"%s\": %s", path_max_tmp, strerror(errno)); while (fclose(file) != 0 && errno == EINTR);
return -1; errno = save_errno;
return PLAYLIST_RESULT_ERRNO;
} }
if (fstat(fileno(file), &st) < 0) { if (fstat(fileno(file), &st) < 0) {
commandError(fd, ACK_ERROR_NO_EXIST, "could not stat file " int save_errno = errno;
"\"%s\": %s", path_max_tmp, strerror(errno));
while (fclose(file) != 0 && errno == EINTR); while (fclose(file) != 0 && errno == EINTR);
return -1; errno = save_errno;
return PLAYLIST_RESULT_ERRNO;
} }
if (st.st_size >= ((MPD_PATH_MAX+1) * playlist_max_length)) { if (st.st_size >= ((MPD_PATH_MAX+1) * playlist_max_length)) {
while (fclose(file) != 0 && errno == EINTR); while (fclose(file) != 0 && errno == EINTR);
commandError(fd, ACK_ERROR_PLAYLIST_MAX, return PLAYLIST_RESULT_TOO_LARGE;
"playlist is at the max size");
return -1;
} }
s = utf8_to_fs_charset(path_max_tmp2, get_song_url(path_max_tmp, song)); s = utf8_to_fs_charset(path_max_tmp2, get_song_url(path_max_tmp, song));
...@@ -319,40 +299,31 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song) ...@@ -319,40 +299,31 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song)
fprintf(file, "%s\n", s); fprintf(file, "%s\n", s);
while (fclose(file) != 0 && errno == EINTR); while (fclose(file) != 0 && errno == EINTR);
return 0; return PLAYLIST_RESULT_SUCCESS;
} }
int renameStoredPlaylist(int fd, const char *utf8from, const char *utf8to) enum playlist_result
renameStoredPlaylist(const char *utf8from, const char *utf8to)
{ {
struct stat st; struct stat st;
char from[MPD_PATH_MAX]; char from[MPD_PATH_MAX];
char to[MPD_PATH_MAX]; char to[MPD_PATH_MAX];
if (!valid_playlist_name(fd, utf8from) || if (!is_valid_playlist_name(utf8from) ||
!valid_playlist_name(fd, utf8to)) !is_valid_playlist_name(utf8to))
return -1; return PLAYLIST_RESULT_BAD_NAME;
utf8_to_fs_playlist_path(from, utf8from); utf8_to_fs_playlist_path(from, utf8from);
utf8_to_fs_playlist_path(to, utf8to); utf8_to_fs_playlist_path(to, utf8to);
if (stat(from, &st) != 0) { if (stat(from, &st) != 0)
commandError(fd, ACK_ERROR_NO_EXIST, return PLAYLIST_RESULT_NO_SUCH_LIST;
"no playlist named \"%s\"", utf8from);
return -1;
}
if (stat(to, &st) == 0) { if (stat(to, &st) == 0)
commandError(fd, ACK_ERROR_EXIST, "a file or directory " return PLAYLIST_RESULT_LIST_EXISTS;
"already exists with the name \"%s\"", utf8to);
return -1;
}
if (rename(from, to) < 0) { if (rename(from, to) < 0)
commandError(fd, ACK_ERROR_UNKNOWN, return PLAYLIST_RESULT_ERRNO;
"could not rename playlist \"%s\" to \"%s\": %s",
utf8from, utf8to, strerror(errno));
return -1;
}
return 0; return PLAYLIST_RESULT_SUCCESS;
} }
...@@ -23,14 +23,21 @@ ...@@ -23,14 +23,21 @@
#include "list.h" #include "list.h"
#include "playlist.h" #include "playlist.h"
List *loadStoredPlaylist(int fd, const char *utf8path); List *loadStoredPlaylist(const char *utf8path);
int moveSongInStoredPlaylistByPath(int fd, const char *utf8path, int src, int dest); enum playlist_result
int removeAllFromStoredPlaylistByPath(int fd, const char *utf8path); moveSongInStoredPlaylistByPath(const char *utf8path, int src, int dest);
int removeOneSongFromStoredPlaylistByPath(int fd, const char *utf8path, int pos);
int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song); enum playlist_result
removeAllFromStoredPlaylistByPath(const char *utf8path);
int renameStoredPlaylist(int fd, const char *utf8from, const char *utf8to); enum playlist_result
removeOneSongFromStoredPlaylistByPath(const char *utf8path, int pos);
enum playlist_result
appendSongToStoredPlaylistByPath(const char *utf8path, Song *song);
enum playlist_result
renameStoredPlaylist(const char *utf8from, const char *utf8to);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment