aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/command.c20
-rw-r--r--src/directory.c12
-rw-r--r--src/directory.h3
3 files changed, 22 insertions, 13 deletions
diff --git a/src/command.c b/src/command.c
index 616132bea..ce41abb64 100644
--- a/src/command.c
+++ b/src/command.c
@@ -799,6 +799,16 @@ 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;
+ }
+ commandError(fd, ACK_ERROR_UPDATE_ALREADY, "already updating");
+ return -1;
+}
+
static int listHandleUpdate(int fd,
mpd_unused int *permission,
mpd_unused int argc,
@@ -818,7 +828,7 @@ static int listHandleUpdate(int fd,
nextCmd = getCommandEntryFromString(next->data, permission);
if (cmd != nextCmd)
- return updateInit(fd, pathList);
+ return print_update_result(fd, updateInit(pathList));
return 0;
}
@@ -826,12 +836,14 @@ static int listHandleUpdate(int fd,
static int handleUpdate(int fd, mpd_unused int *permission,
mpd_unused int argc, char *argv[])
{
+ List *pathList = NULL;
+
if (argc == 2) {
- List *pathList = makeList(NULL, 1);
+ pathList = makeList(NULL, 1);
insertInList(pathList, argv[1], NULL);
- return updateInit(fd, pathList);
}
- return updateInit(fd, NULL);
+
+ return print_update_result(fd, updateInit(pathList));
}
static int handleNext(mpd_unused int fd, mpd_unused int *permission,
diff --git a/src/directory.c b/src/directory.c
index 124ea194e..a332316ff 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -18,7 +18,6 @@
#include "directory.h"
-#include "command.h"
#include "conf.h"
#include "log.h"
#include "ls.h"
@@ -148,14 +147,13 @@ out:
return (void *)ret;
}
-int updateInit(int fd, List * path_list)
+int updateInit(List * path_list)
{
pthread_attr_t attr;
- if (progress != UPDATE_PROGRESS_IDLE) {
- commandError(fd, ACK_ERROR_UPDATE_ALREADY, "already updating");
+ if (progress != UPDATE_PROGRESS_IDLE)
return -1;
- }
+
progress = UPDATE_PROGRESS_RUNNING;
pthread_attr_init(&attr);
@@ -166,9 +164,7 @@ int updateInit(int fd, List * path_list)
directory_updateJobId = 1;
DEBUG("updateInit: spawned update thread for update job id %i\n",
(int)directory_updateJobId);
- fdprintf(fd, "updating_db: %i\n", (int)directory_updateJobId);
-
- return 0;
+ return directory_updateJobId;
}
static void directory_set_stat(Directory * dir, const struct stat *st)
diff --git a/src/directory.h b/src/directory.h
index 5c4c76a25..9161efc38 100644
--- a/src/directory.h
+++ b/src/directory.h
@@ -42,7 +42,8 @@ void reap_update_task(void);
int isUpdatingDB(void);
-int updateInit(int fd, List * pathList);
+/* returns the non-negative update job ID on success, -1 on error */
+int updateInit(List * pathList);
void directory_init(void);