diff options
author | Max Kellermann <max@duempel.org> | 2014-01-30 20:39:36 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-30 20:39:40 +0100 |
commit | 34b309b99aa2f274308f19974c428e1c7ac5d66f (patch) | |
tree | 1150ec321cf90a9e765bb58872f79fdc07ef1e10 | |
parent | c6725884bc155da431889468c86c546f0f64f9a1 (diff) | |
download | mpd-34b309b99aa2f274308f19974c428e1c7ac5d66f.tar.gz mpd-34b309b99aa2f274308f19974c428e1c7ac5d66f.tar.xz mpd-34b309b99aa2f274308f19974c428e1c7ac5d66f.zip |
OtherCommands: merge duplicate code from handle_update(), handle_rescan()
-rw-r--r-- | src/command/OtherCommands.cxx | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx index 2aa67f22c..3c546b9b4 100644 --- a/src/command/OtherCommands.cxx +++ b/src/command/OtherCommands.cxx @@ -183,8 +183,8 @@ handle_lsinfo(Client &client, int argc, char *argv[]) return CommandResult::OK; } -CommandResult -handle_update(Client &client, gcc_unused int argc, char *argv[]) +static CommandResult +handle_update(Client &client, int argc, char *argv[], bool discard) { const char *path = ""; @@ -208,7 +208,7 @@ handle_update(Client &client, gcc_unused int argc, char *argv[]) return CommandResult::ERROR; } - unsigned ret = update->Enqueue(path, false); + unsigned ret = update->Enqueue(path, discard); if (ret > 0) { client_printf(client, "updating_db: %i\n", ret); return CommandResult::OK; @@ -220,36 +220,15 @@ handle_update(Client &client, gcc_unused int argc, char *argv[]) } CommandResult -handle_rescan(Client &client, gcc_unused int argc, char *argv[]) +handle_update(Client &client, gcc_unused int argc, char *argv[]) { - const char *path = ""; - - assert(argc <= 2); - if (argc == 2) { - path = argv[1]; - - if (!uri_safe_local(path)) { - command_error(client, ACK_ERROR_ARG, - "Malformed path"); - return CommandResult::ERROR; - } - } - - UpdateService *update = client.partition.instance.update; - if (update == nullptr) { - command_error(client, ACK_ERROR_NO_EXIST, "No database"); - return CommandResult::ERROR; - } + return handle_update(client, argc, argv, false); +} - unsigned ret = update->Enqueue(path, true); - if (ret > 0) { - client_printf(client, "updating_db: %i\n", ret); - return CommandResult::OK; - } else { - command_error(client, ACK_ERROR_UPDATE_ALREADY, - "already updating"); - return CommandResult::ERROR; - } +CommandResult +handle_rescan(Client &client, gcc_unused int argc, char *argv[]) +{ + return handle_update(client, argc, argv, true); } CommandResult |