db/update/Service: Enqueue() throws on error
This commit is contained in:
parent
9999914c74
commit
cc64c715a2
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<SimpleDatabase *>(&_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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user