int kr_adapter_prepare(kr_adapter *adapter) { int i; int processed; processed = 0; for (i = 0; i < KR_ADAPTER_PATHS_MAX; i++) { if (adapter->path[i] != NULL) { processed += path_prepare(adapter->path[i]); } } return processed; }
int cmd_add (int argc, char ** argv, struct mpd_connection *conn ) { if (contains_absolute_path(argc, argv) && !path_prepare(conn)) printErrorAndExit(conn); int i; if (!mpd_command_list_begin(conn, false)) printErrorAndExit(conn); for(i=0;i<argc;i++) { strip_trailing_slash(argv[i]); const char *path = argv[i]; const char *relative_path = to_relative_path(path); if (relative_path != NULL) path = relative_path; if (options.verbosity >= V_VERBOSE) printf("adding: %s\n", path); mpd_send_add(conn, charset_to_utf8(path)); } if (!mpd_command_list_end(conn)) printErrorAndExit(conn); if (!mpd_response_finish(conn)) { #if LIBMPDCLIENT_CHECK_VERSION(2,4,0) if (mpd_connection_get_error(conn) == MPD_ERROR_SERVER) { /* check which of the arguments has failed */ unsigned location = mpd_connection_get_server_error_location(conn); if (location < (unsigned)argc) { /* we've got a valid location from the server */ const char *message = mpd_connection_get_error_message(conn); message = charset_from_utf8(message); fprintf(stderr, "error adding %s: %s\n", argv[location], message); exit(EXIT_FAILURE); } } #endif printErrorAndExit(conn); } return 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; }