unsigned mpd_run_rescan(struct mpd_connection *connection, const char *path) { unsigned id; if (!mpd_run_check(connection) || !mpd_send_rescan(connection, path)) return 0; id = mpd_recv_update_id(connection); return id != 0 && mpd_response_finish(connection) ? id : 0; }
int cmd_update(int argc, char **argv, struct mpd_connection *conn) { if (contains_absolute_path(argc, argv) && !path_prepare(conn)) printErrorAndExit(conn); if (!mpd_command_list_begin(conn, false)) printErrorAndExit(conn); int i = 0; const char *update = ""; if (argc > 0) update = charset_to_utf8(argv[i]); do { char *tmp = strdup(update); strip_trailing_slash(tmp); const char *path = tmp; const char *relative_path = to_relative_path(path); if (relative_path != NULL) path = relative_path; mpd_send_update(conn, path); free(tmp); } while (++i < argc && (update = charset_to_utf8(argv[i])) != NULL); if (!mpd_command_list_end(conn)) printErrorAndExit(conn); /* obtain the last "update id" response */ unsigned id = 0; while (true) { unsigned next_id = mpd_recv_update_id(conn); if (next_id == 0) break; id = next_id; } my_finishCommand(conn); while (options.wait) { /* idle until an update finishes */ enum mpd_idle idle = mpd_run_idle_mask(conn, MPD_IDLE_UPDATE); struct mpd_status *status; unsigned current_id; if (idle == 0) printErrorAndExit(conn); /* determine the current "update id" */ status = getStatus(conn); current_id = mpd_status_get_update_id(status); mpd_status_free(status); /* is our last queued update finished now? */ if (current_id == 0 || current_id > id || (id > 1 << 30 && id < 1000)) /* wraparound */ break; } return 1; }