aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-17 20:57:56 +0100
committerMax Kellermann <max@duempel.org>2014-02-19 23:24:17 +0100
commit150443b014e3df20d9fcac0de88ff32574e4c471 (patch)
tree188ed2e936b6727f0c432ccb8d24871f125bb0cd
parent9e36af791615eb8adcaee956808421271cb1ddff (diff)
downloadmpd-150443b014e3df20d9fcac0de88ff32574e4c471.tar.gz
mpd-150443b014e3df20d9fcac0de88ff32574e4c471.tar.xz
mpd-150443b014e3df20d9fcac0de88ff32574e4c471.zip
DatabasePlugin: add FLAG_REQUIRE_STORAGE
Ignore the storage configuration if FLAG_REQUIRE_STORAGE is not set in the DatabasePlugin.
-rw-r--r--src/Main.cxx26
-rw-r--r--src/db/DatabasePlugin.hxx10
-rw-r--r--src/db/plugins/ProxyDatabasePlugin.cxx2
-rw-r--r--src/db/plugins/SimpleDatabasePlugin.cxx2
-rw-r--r--src/storage/Configured.cxx6
-rw-r--r--src/storage/Configured.hxx8
6 files changed, 43 insertions, 11 deletions
diff --git a/src/Main.cxx b/src/Main.cxx
index 8fe90fc6f..368f54caa 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -67,6 +67,7 @@
#ifdef ENABLE_DATABASE
#include "db/update/Service.hxx"
#include "db/Configured.hxx"
+#include "db/DatabasePlugin.hxx"
#include "db/plugins/SimpleDatabasePlugin.hxx"
#include "storage/Configured.hxx"
#include "storage/CompositeStorage.hxx"
@@ -177,16 +178,23 @@ glue_db_init_and_load(void)
return true;
}
- if (!InitStorage(error))
- FatalError(error);
+ if (instance->database->GetPlugin().flags & DatabasePlugin::FLAG_REQUIRE_STORAGE) {
+ if (!InitStorage(error))
+ FatalError(error);
- if (instance->storage == nullptr) {
- delete instance->database;
- instance->database = nullptr;
- LogDefault(config_domain,
- "Found database setting without "
- "music_directory - disabling database");
- return true;
+ if (instance->storage == nullptr) {
+ delete instance->database;
+ instance->database = nullptr;
+ LogDefault(config_domain,
+ "Found database setting without "
+ "music_directory - disabling database");
+ return true;
+ }
+ } else {
+ if (IsStorageConfigured())
+ LogDefault(config_domain,
+ "Ignoring the storage configuration "
+ "because the database does not need it");
}
if (!instance->database->Open(error))
diff --git a/src/db/DatabasePlugin.hxx b/src/db/DatabasePlugin.hxx
index 7655d8e2d..831101786 100644
--- a/src/db/DatabasePlugin.hxx
+++ b/src/db/DatabasePlugin.hxx
@@ -33,6 +33,12 @@ class DatabaseListener;
class Database;
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;
unsigned flags;
@@ -43,6 +49,10 @@ struct DatabasePlugin {
Database *(*create)(EventLoop &loop, DatabaseListener &listener,
const config_param &param,
Error &error);
+
+ constexpr bool RequireStorage() const {
+ return flags & FLAG_REQUIRE_STORAGE;
+ }
};
#endif
diff --git a/src/db/plugins/ProxyDatabasePlugin.cxx b/src/db/plugins/ProxyDatabasePlugin.cxx
index 824c1af46..e46b4b9e8 100644
--- a/src/db/plugins/ProxyDatabasePlugin.cxx
+++ b/src/db/plugins/ProxyDatabasePlugin.cxx
@@ -780,6 +780,6 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection,
const DatabasePlugin proxy_db_plugin = {
"proxy",
- 0,
+ DatabasePlugin::FLAG_REQUIRE_STORAGE,
ProxyDatabase::Create,
};
diff --git a/src/db/plugins/SimpleDatabasePlugin.cxx b/src/db/plugins/SimpleDatabasePlugin.cxx
index 8632fa5af..48d014e55 100644
--- a/src/db/plugins/SimpleDatabasePlugin.cxx
+++ b/src/db/plugins/SimpleDatabasePlugin.cxx
@@ -337,6 +337,6 @@ SimpleDatabase::Save(Error &error)
const DatabasePlugin simple_db_plugin = {
"simple",
- 0,
+ DatabasePlugin::FLAG_REQUIRE_STORAGE,
SimpleDatabase::Create,
};
diff --git a/src/storage/Configured.cxx b/src/storage/Configured.cxx
index ab0135935..29e511c7a 100644
--- a/src/storage/Configured.cxx
+++ b/src/storage/Configured.cxx
@@ -76,3 +76,9 @@ CreateConfiguredStorage(Error &error)
return CreateConfiguredStorageLocal(error);
}
+
+bool
+IsStorageConfigured()
+{
+ return config_get_string(CONF_MUSIC_DIR, nullptr) != nullptr;
+}
diff --git a/src/storage/Configured.hxx b/src/storage/Configured.hxx
index ec9621c64..d78857a26 100644
--- a/src/storage/Configured.hxx
+++ b/src/storage/Configured.hxx
@@ -21,6 +21,7 @@
#define MPD_STORAGE_CONFIG_HXX
#include "check.h"
+#include "Compiler.h"
class Error;
class Storage;
@@ -33,4 +34,11 @@ class Storage;
Storage *
CreateConfiguredStorage(Error &error);
+/**
+ * Returns true if there is configuration for a #Storage instance.
+ */
+gcc_const
+bool
+IsStorageConfigured();
+
#endif