From 34b309b99aa2f274308f19974c428e1c7ac5d66f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 30 Jan 2014 20:39:36 +0100 Subject: [PATCH] OtherCommands: merge duplicate code from handle_update(), handle_rescan() --- src/command/OtherCommands.cxx | 41 +++++++++-------------------------- 1 file 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; @@ -219,37 +219,16 @@ handle_update(Client &client, gcc_unused int argc, char *argv[]) } } +CommandResult +handle_update(Client &client, gcc_unused int argc, char *argv[]) +{ + return handle_update(client, argc, argv, false); +} + CommandResult handle_rescan(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; - } - - 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; - } + return handle_update(client, argc, argv, true); } CommandResult