Commit 150443b0 authored by Max Kellermann's avatar Max Kellermann

DatabasePlugin: add FLAG_REQUIRE_STORAGE

Ignore the storage configuration if FLAG_REQUIRE_STORAGE is not set in the DatabasePlugin.
parent 9e36af79
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
#include "db/update/Service.hxx" #include "db/update/Service.hxx"
#include "db/Configured.hxx" #include "db/Configured.hxx"
#include "db/DatabasePlugin.hxx"
#include "db/plugins/SimpleDatabasePlugin.hxx" #include "db/plugins/SimpleDatabasePlugin.hxx"
#include "storage/Configured.hxx" #include "storage/Configured.hxx"
#include "storage/CompositeStorage.hxx" #include "storage/CompositeStorage.hxx"
...@@ -177,6 +178,7 @@ glue_db_init_and_load(void) ...@@ -177,6 +178,7 @@ glue_db_init_and_load(void)
return true; return true;
} }
if (instance->database->GetPlugin().flags & DatabasePlugin::FLAG_REQUIRE_STORAGE) {
if (!InitStorage(error)) if (!InitStorage(error))
FatalError(error); FatalError(error);
...@@ -188,6 +190,12 @@ glue_db_init_and_load(void) ...@@ -188,6 +190,12 @@ glue_db_init_and_load(void)
"music_directory - disabling database"); "music_directory - disabling database");
return true; return true;
} }
} else {
if (IsStorageConfigured())
LogDefault(config_domain,
"Ignoring the storage configuration "
"because the database does not need it");
}
if (!instance->database->Open(error)) if (!instance->database->Open(error))
FatalError(error); FatalError(error);
......
...@@ -33,6 +33,12 @@ class DatabaseListener; ...@@ -33,6 +33,12 @@ class DatabaseListener;
class Database; class Database;
struct DatabasePlugin { struct DatabasePlugin {
/**
* This plugin requires a #Storage instance. It contains only
* cached metadata from files in the #Storage.
*/
static constexpr unsigned FLAG_REQUIRE_STORAGE = 0x1;
const char *name; const char *name;
unsigned flags; unsigned flags;
...@@ -43,6 +49,10 @@ struct DatabasePlugin { ...@@ -43,6 +49,10 @@ struct DatabasePlugin {
Database *(*create)(EventLoop &loop, DatabaseListener &listener, Database *(*create)(EventLoop &loop, DatabaseListener &listener,
const config_param &param, const config_param &param,
Error &error); Error &error);
constexpr bool RequireStorage() const {
return flags & FLAG_REQUIRE_STORAGE;
}
}; };
#endif #endif
...@@ -780,6 +780,6 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection, ...@@ -780,6 +780,6 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection,
const DatabasePlugin proxy_db_plugin = { const DatabasePlugin proxy_db_plugin = {
"proxy", "proxy",
0, DatabasePlugin::FLAG_REQUIRE_STORAGE,
ProxyDatabase::Create, ProxyDatabase::Create,
}; };
...@@ -337,6 +337,6 @@ SimpleDatabase::Save(Error &error) ...@@ -337,6 +337,6 @@ SimpleDatabase::Save(Error &error)
const DatabasePlugin simple_db_plugin = { const DatabasePlugin simple_db_plugin = {
"simple", "simple",
0, DatabasePlugin::FLAG_REQUIRE_STORAGE,
SimpleDatabase::Create, SimpleDatabase::Create,
}; };
...@@ -76,3 +76,9 @@ CreateConfiguredStorage(Error &error) ...@@ -76,3 +76,9 @@ CreateConfiguredStorage(Error &error)
return CreateConfiguredStorageLocal(error); return CreateConfiguredStorageLocal(error);
} }
bool
IsStorageConfigured()
{
return config_get_string(CONF_MUSIC_DIR, nullptr) != nullptr;
}
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define MPD_STORAGE_CONFIG_HXX #define MPD_STORAGE_CONFIG_HXX
#include "check.h" #include "check.h"
#include "Compiler.h"
class Error; class Error;
class Storage; class Storage;
...@@ -33,4 +34,11 @@ class Storage; ...@@ -33,4 +34,11 @@ class Storage;
Storage * Storage *
CreateConfiguredStorage(Error &error); CreateConfiguredStorage(Error &error);
/**
* Returns true if there is configuration for a #Storage instance.
*/
gcc_const
bool
IsStorageConfigured();
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment