storage/Configured: use struct ConfigData

This commit is contained in:
Max Kellermann 2018-07-17 22:57:08 +02:00
parent 667daab056
commit d2594c6380
3 changed files with 17 additions and 16 deletions

View File

@ -166,9 +166,9 @@ glue_mapper_init(const ConfigData &config)
#ifdef ENABLE_DATABASE
static void
InitStorage(EventLoop &event_loop)
InitStorage(const ConfigData &config, EventLoop &event_loop)
{
auto storage = CreateConfiguredStorage(event_loop);
auto storage = CreateConfiguredStorage(config, event_loop);
if (storage == nullptr)
return;
@ -193,7 +193,7 @@ glue_db_init_and_load(const ConfigData &config)
return true;
if (instance->database->GetPlugin().flags & DatabasePlugin::FLAG_REQUIRE_STORAGE) {
InitStorage(instance->io_thread.GetEventLoop());
InitStorage(config, instance->io_thread.GetEventLoop());
if (instance->storage == nullptr) {
delete instance->database;
@ -204,7 +204,7 @@ glue_db_init_and_load(const ConfigData &config)
return true;
}
} else {
if (IsStorageConfigured())
if (IsStorageConfigured(config))
LogDefault(config_domain,
"Ignoring the storage configuration "
"because the database does not need it");

View File

@ -22,7 +22,7 @@
#include "Registry.hxx"
#include "StorageInterface.hxx"
#include "plugins/LocalStorage.hxx"
#include "config/Global.hxx"
#include "config/Data.hxx"
#include "config/Domain.hxx"
#include "fs/StandardDirectory.hxx"
#include "fs/CheckFile.hxx"
@ -42,9 +42,9 @@ CreateConfiguredStorageUri(EventLoop &event_loop, const char *uri)
}
static AllocatedPath
GetConfiguredMusicDirectory()
GetConfiguredMusicDirectory(const ConfigData &config)
{
AllocatedPath path = config_get_path(ConfigOption::MUSIC_DIR);
AllocatedPath path = config.GetPath(ConfigOption::MUSIC_DIR);
if (path.IsNull())
path = GetUserMusicDir();
@ -52,9 +52,9 @@ GetConfiguredMusicDirectory()
}
static std::unique_ptr<Storage>
CreateConfiguredStorageLocal()
CreateConfiguredStorageLocal(const ConfigData &config)
{
AllocatedPath path = GetConfiguredMusicDirectory();
AllocatedPath path = GetConfiguredMusicDirectory(config);
if (path.IsNull())
return nullptr;
@ -64,17 +64,17 @@ CreateConfiguredStorageLocal()
}
std::unique_ptr<Storage>
CreateConfiguredStorage(EventLoop &event_loop)
CreateConfiguredStorage(const ConfigData &config, EventLoop &event_loop)
{
auto uri = config_get_string(ConfigOption::MUSIC_DIR);
auto uri = config.GetString(ConfigOption::MUSIC_DIR);
if (uri != nullptr && uri_has_scheme(uri))
return CreateConfiguredStorageUri(event_loop, uri);
return CreateConfiguredStorageLocal();
return CreateConfiguredStorageLocal(config);
}
bool
IsStorageConfigured() noexcept
IsStorageConfigured(const ConfigData &config) noexcept
{
return config_get_string(ConfigOption::MUSIC_DIR) != nullptr;
return config.GetParam(ConfigOption::MUSIC_DIR) != nullptr;
}

View File

@ -25,6 +25,7 @@
#include <memory>
struct ConfigData;
class Storage;
class EventLoop;
@ -35,13 +36,13 @@ class EventLoop;
* Throws #std::runtime_error on error.
*/
std::unique_ptr<Storage>
CreateConfiguredStorage(EventLoop &event_loop);
CreateConfiguredStorage(const ConfigData &config, EventLoop &event_loop);
/**
* Returns true if there is configuration for a #Storage instance.
*/
gcc_const
bool
IsStorageConfigured() noexcept;
IsStorageConfigured(const ConfigData &config) noexcept;
#endif