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().
This commit is contained in:
		| @@ -803,31 +803,27 @@ static int handlePlaylistMove(struct client *client, | |||||||
| 	return print_playlist_result(client, result); | 	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, | static int handleUpdate(struct client *client, | ||||||
| 			mpd_unused int argc, char *argv[]) | 			mpd_unused int argc, char *argv[]) | ||||||
| { | { | ||||||
| 	char *path = NULL; | 	char *path = NULL; | ||||||
|  | 	int ret; | ||||||
|  |  | ||||||
| 	assert(argc <= 2); | 	assert(argc <= 2); | ||||||
| 	if (argc == 2 && !(path = sanitizePathDup(argv[1]))) { | 	if (argc == 2 && !(path = sanitizePathDup(argv[1]))) { | ||||||
| 		command_error(client, ACK_ERROR_ARG, "invalid path"); | 		command_error(client, ACK_ERROR_ARG, "invalid path"); | ||||||
| 		return -1; | 		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, | static int handleNext(mpd_unused struct client *client, | ||||||
|   | |||||||
| @@ -46,7 +46,7 @@ db_init(void) | |||||||
| 	music_root = directory_new("", NULL); | 	music_root = directory_new("", NULL); | ||||||
|  |  | ||||||
| 	ret = directory_update_init(NULL); | 	ret = directory_update_init(NULL); | ||||||
| 	if (ret < 0) | 	if (ret == 0) | ||||||
| 		FATAL("directory update failed\n"); | 		FATAL("directory update failed\n"); | ||||||
|  |  | ||||||
| 	do { | 	do { | ||||||
|   | |||||||
| @@ -436,9 +436,9 @@ int directory_update_init(char *path) | |||||||
| 		int next_task_id; | 		int next_task_id; | ||||||
|  |  | ||||||
| 		if (!path) | 		if (!path) | ||||||
| 			return -1; | 			return 0; | ||||||
| 		if (update_paths_nr == ARRAY_SIZE(update_paths)) | 		if (update_paths_nr == ARRAY_SIZE(update_paths)) | ||||||
| 			return -1; | 			return 0; | ||||||
| 		assert(update_paths_nr < ARRAY_SIZE(update_paths)); | 		assert(update_paths_nr < ARRAY_SIZE(update_paths)); | ||||||
| 		update_paths[update_paths_nr++] = path; | 		update_paths[update_paths_nr++] = path; | ||||||
| 		next_task_id = update_task_id + update_paths_nr; | 		next_task_id = update_task_id + update_paths_nr; | ||||||
|   | |||||||
| @@ -23,8 +23,8 @@ | |||||||
| int isUpdatingDB(void); | int isUpdatingDB(void); | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * returns the non-negative update job ID on success, |  * returns the positive update job ID on success, | ||||||
|  * returns -1 if busy |  * returns 0 if busy | ||||||
|  * @path will be freed by this function and should not be reused |  * @path will be freed by this function and should not be reused | ||||||
|  */ |  */ | ||||||
| int directory_update_init(char *path); | int directory_update_init(char *path); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann