diff options
author | Max Kellermann <max@duempel.org> | 2008-10-09 19:17:44 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-09 19:17:44 +0200 |
commit | f1022bcc12dbdf5b7974fb1510197b12214fec32 (patch) | |
tree | cabe38f9e1f728423b03bab187e6c55157ffad8d | |
parent | 79a28e5c72ae01164b88ae6d8a510f47a92d231f (diff) | |
download | mpd-f1022bcc12dbdf5b7974fb1510197b12214fec32.tar.gz mpd-f1022bcc12dbdf5b7974fb1510197b12214fec32.tar.xz mpd-f1022bcc12dbdf5b7974fb1510197b12214fec32.zip |
update: job ID must be positive
The documentation for directory_update_init() was incorrect: a job ID
must be positive, not non-negative. If the update queue is full and
no job was created, it makes more sense to return 0 instead of -1,
because it is more consistent with the return value of isUpdatingDB().
-rw-r--r-- | src/command.c | 26 | ||||
-rw-r--r-- | src/database.c | 2 | ||||
-rw-r--r-- | src/update.c | 4 | ||||
-rw-r--r-- | src/update.h | 4 |
4 files changed, 16 insertions, 20 deletions
diff --git a/src/command.c b/src/command.c index c98bc20e7..1d2645cd1 100644 --- a/src/command.c +++ b/src/command.c @@ -803,31 +803,27 @@ static int handlePlaylistMove(struct client *client, return print_playlist_result(client, result); } -static int print_update_result(struct client *client, int ret) -{ - if (ret >= 0) { - client_printf(client, "updating_db: %i\n", ret); - return 0; - } - if (ret == -2) - command_error(client, ACK_ERROR_ARG, "invalid path"); - else - command_error(client, ACK_ERROR_UPDATE_ALREADY, - "already updating"); - return -1; -} - static int handleUpdate(struct client *client, mpd_unused int argc, char *argv[]) { char *path = NULL; + int ret; assert(argc <= 2); if (argc == 2 && !(path = sanitizePathDup(argv[1]))) { command_error(client, ACK_ERROR_ARG, "invalid path"); return -1; } - return print_update_result(client, directory_update_init(path)); + + ret = directory_update_init(path); + if (ret > 0) { + client_printf(client, "updating_db: %i\n", ret); + return 0; + } else { + command_error(client, ACK_ERROR_UPDATE_ALREADY, + "already updating"); + return -1; + } } static int handleNext(mpd_unused struct client *client, diff --git a/src/database.c b/src/database.c index bd069f8b4..2581e408b 100644 --- a/src/database.c +++ b/src/database.c @@ -46,7 +46,7 @@ db_init(void) music_root = directory_new("", NULL); ret = directory_update_init(NULL); - if (ret < 0) + if (ret == 0) FATAL("directory update failed\n"); do { diff --git a/src/update.c b/src/update.c index 9cb3739be..a962cca98 100644 --- a/src/update.c +++ b/src/update.c @@ -436,9 +436,9 @@ int directory_update_init(char *path) int next_task_id; if (!path) - return -1; + return 0; if (update_paths_nr == ARRAY_SIZE(update_paths)) - return -1; + return 0; assert(update_paths_nr < ARRAY_SIZE(update_paths)); update_paths[update_paths_nr++] = path; next_task_id = update_task_id + update_paths_nr; diff --git a/src/update.h b/src/update.h index 0c0d74416..5c7277e32 100644 --- a/src/update.h +++ b/src/update.h @@ -23,8 +23,8 @@ int isUpdatingDB(void); /* - * returns the non-negative update job ID on success, - * returns -1 if busy + * returns the positive update job ID on success, + * returns 0 if busy * @path will be freed by this function and should not be reused */ int directory_update_init(char *path); |