From cc64c715a200836f40b3d231e8b01a64ce8e9eda Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 19 Aug 2018 23:15:52 +0200 Subject: [PATCH] db/update/Service: Enqueue() throws on error --- src/Main.cxx | 4 +--- src/command/OtherCommands.cxx | 9 ++------- src/db/update/Service.cxx | 9 +++++---- src/db/update/Service.hxx | 4 +++- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Main.cxx b/src/Main.cxx index e7d7a6db0..9a56ad4e9 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -617,9 +617,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) if (create_db) { /* the database failed to load: recreate the database */ - unsigned job = instance->update->Enqueue("", true); - if (job == 0) - throw std::runtime_error("directory update failed"); + instance->update->Enqueue("", true); } #endif diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx index 228d5ea40..ac794ee33 100644 --- a/src/command/OtherCommands.cxx +++ b/src/command/OtherCommands.cxx @@ -249,13 +249,8 @@ handle_update(Response &r, UpdateService &update, const char *uri_utf8, bool discard) { unsigned ret = update.Enqueue(uri_utf8, discard); - if (ret > 0) { - r.Format("updating_db: %i\n", ret); - return CommandResult::OK; - } else { - r.Error(ACK_ERROR_UPDATE_ALREADY, "already updating"); - return CommandResult::ERROR; - } + r.Format("updating_db: %i\n", ret); + return CommandResult::OK; } static CommandResult diff --git a/src/db/update/Service.cxx b/src/db/update/Service.cxx index 9f7211933..debd9c432 100644 --- a/src/db/update/Service.cxx +++ b/src/db/update/Service.cxx @@ -26,6 +26,7 @@ #include "db/plugins/simple/SimpleDatabasePlugin.hxx" #include "db/plugins/simple/Directory.hxx" #include "storage/CompositeStorage.hxx" +#include "protocol/Ack.hxx" #include "Idle.hxx" #include "Log.hxx" #include "thread/Thread.hxx" @@ -192,8 +193,7 @@ UpdateService::Enqueue(const char *path, bool discard) Database &_db2 = *lr.directory->mounted_database; if (!_db2.IsPlugin(simple_db_plugin)) - /* cannot update this type of database */ - return 0; + throw std::runtime_error("Cannot update this type of database"); db2 = static_cast(&_db2); @@ -219,12 +219,13 @@ UpdateService::Enqueue(const char *path, bool discard) if (storage2 == nullptr) /* no storage found at this mount point - should not happen */ - return 0; + throw std::runtime_error("No storage at this path"); if (walk != nullptr) { const unsigned id = GenerateId(); if (!queue.Push(*db2, *storage2, path, discard, id)) - return 0; + throw ProtocolError(ACK_ERROR_UPDATE_ALREADY, + "Update queue is full"); update_task_id = id; return id; diff --git a/src/db/update/Service.hxx b/src/db/update/Service.hxx index e8818fd46..3f6284772 100644 --- a/src/db/update/Service.hxx +++ b/src/db/update/Service.hxx @@ -82,9 +82,11 @@ public: /** * Add this path to the database update queue. * + * Throws on error + * * @param path a path to update; if an empty string, * the whole music directory is updated - * @return the job id, or 0 on error + * @return the job id */ gcc_nonnull_all unsigned Enqueue(const char *path, bool discard);