aboutsummaryrefslogtreecommitdiffstats
path: root/src/command.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-29 03:05:14 -0700
committerEric Wong <normalperson@yhbt.net>2008-09-29 03:05:14 -0700
commitc4772b46eedc41cbe40678be1c02f31d24117b5e (patch)
treea43100a40f5f30d95dabacd98a9e372930b5bc5e /src/command.c
parent1e36728aedede8f521b622ef32ca102e79cb61f6 (diff)
parentdde461fe6e012a62ee47cf5f3bfc022b650b6bf5 (diff)
downloadmpd-c4772b46eedc41cbe40678be1c02f31d24117b5e.tar.gz
mpd-c4772b46eedc41cbe40678be1c02f31d24117b5e.tar.xz
mpd-c4772b46eedc41cbe40678be1c02f31d24117b5e.zip
Merge branch 'ew/directory'
* ew/directory: directory: remove redundant sanitizePathDup update: move path sanitation up the stack to avoid extra copies clean up updateInit calling and error handling directory: isRootDirectory() is a one-liner directory: writeDirectoryInfo propagates errors directory: make it clear that DIRECTORY_MTIME is deprecated directory: remove "Mp3" references playlist: deleteASongFromPlaylist takes a const Song * songvec: songvec_delete takes a const Song pointer directory: remove shortname arguments everywhere path: add mpd_basename() function directory.h: remove directory_sigChldHandler decl directory: replace DirectoryList with dirvec directory: remove unused CPP defines songvec_free => songvec_destroy directory.c: kill unnecessary includes
Diffstat (limited to 'src/command.c')
-rw-r--r--src/command.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/command.c b/src/command.c
index 3d4e2ccd5..3f80dc916 100644
--- a/src/command.c
+++ b/src/command.c
@@ -36,6 +36,7 @@
#include "os_compat.h"
#include "player_error.h"
#include "outputBuffer.h"
+#include "path.h"
#define COMMAND_PLAY "play"
#define COMMAND_PLAYID "playid"
@@ -799,26 +800,47 @@ static int handlePlaylistMove(int fd, mpd_unused int *permission,
return print_playlist_result(fd, result);
}
+static int print_update_result(int fd, int ret)
+{
+ if (ret >= 0) {
+ fdprintf(fd, "updating_db: %i\n", ret);
+ return 0;
+ }
+ if (ret == -2)
+ commandError(fd, ACK_ERROR_ARG, "invalid path");
+ else
+ commandError(fd, ACK_ERROR_UPDATE_ALREADY, "already updating");
+ return -1;
+}
+
static int listHandleUpdate(int fd,
mpd_unused int *permission,
mpd_unused int argc,
char *argv[],
struct strnode *cmdnode, CommandEntry * cmd)
{
- List *pathList = makeList(NULL, 1);
+ static char **pathv;
+ static int pathc;
CommandEntry *nextCmd = NULL;
struct strnode *next = cmdnode->next;
+ int last = pathc++;
- if (argc == 2)
- insertInList(pathList, argv[1], NULL);
- else
- insertInList(pathList, "", NULL);
+ pathv = xrealloc(pathv, pathc * sizeof(char *));
+ pathv[last] = sanitizePathDup(argc == 2 ? argv[1] : "");
if (next)
nextCmd = getCommandEntryFromString(next->data, permission);
- if (cmd != nextCmd)
- return updateInit(fd, pathList);
+ if (cmd != nextCmd) {
+ int ret = print_update_result(fd, updateInit(pathc, pathv));
+ if (pathc) {
+ assert(pathv);
+ free(pathv);
+ pathv = NULL;
+ pathc = 0;
+ }
+ return ret;
+ }
return 0;
}
@@ -826,12 +848,12 @@ static int listHandleUpdate(int fd,
static int handleUpdate(int fd, mpd_unused int *permission,
mpd_unused int argc, char *argv[])
{
- if (argc == 2) {
- List *pathList = makeList(NULL, 1);
- insertInList(pathList, argv[1], NULL);
- return updateInit(fd, pathList);
- }
- return updateInit(fd, NULL);
+ char *pathv[1];
+
+ assert(argc <= 2);
+ if (argc == 2)
+ pathv[0] = sanitizePathDup(argv[1]);
+ return print_update_result(fd, updateInit(argc - 1, pathv));
}
static int handleNext(mpd_unused int fd, mpd_unused int *permission,