aboutsummaryrefslogtreecommitdiffstats
path: root/src/command.c
diff options
context:
space:
mode:
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,