aboutsummaryrefslogtreecommitdiffstats
path: root/src/Main.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Main.cxx47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/Main.cxx b/src/Main.cxx
index b0cc74f44..eb71372eb 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -135,38 +135,40 @@ glue_daemonize_init(const struct options *options, Error &error)
static bool
glue_mapper_init(Error &error)
{
- auto music_dir = config_get_path(CONF_MUSIC_DIR, error);
- if (music_dir.IsNull() && error.IsDefined())
- return false;
-
auto playlist_dir = config_get_path(CONF_PLAYLIST_DIR, error);
if (playlist_dir.IsNull() && error.IsDefined())
return false;
- if (music_dir.IsNull())
- music_dir = GetUserMusicDir();
-
- if (!music_dir.IsNull()) {
- music_dir.ChopSeparators();
- CheckDirectoryReadable(music_dir);
- }
+ mapper_init(std::move(playlist_dir));
+ return true;
+}
#ifdef ENABLE_DATABASE
- if (!music_dir.IsNull()) {
- const auto music_dir_utf8 = music_dir.ToUTF8();
- assert(!music_dir_utf8.empty());
- instance->storage = CreateLocalStorage(music_dir_utf8.c_str(),
- music_dir);
+static bool
+InitStorage(Error &error)
+{
+ auto path_fs = config_get_path(CONF_MUSIC_DIR, error);
+ if (path_fs.IsNull() && error.IsDefined())
+ return false;
+
+ if (path_fs.IsNull()) {
+ path_fs = GetUserMusicDir();
+ if (path_fs.IsNull())
+ /* no music directory; that's ok */
+ return true;
}
-#endif
- mapper_init(std::move(playlist_dir));
+ path_fs.ChopSeparators();
+ CheckDirectoryReadable(path_fs);
+
+ const auto utf8 = path_fs.ToUTF8();
+ assert(!utf8.empty());
+
+ instance->storage = CreateLocalStorage(utf8.c_str(), path_fs);
return true;
}
-#ifdef ENABLE_DATABASE
-
/**
* Returns the database. If this function returns false, this has not
* succeeded, and the caller should create the database after the
@@ -480,6 +482,11 @@ int mpd_main(int argc, char *argv[])
decoder_plugin_init_all();
#ifdef ENABLE_DATABASE
+ if (!InitStorage(error)) {
+ LogError(error);
+ return EXIT_FAILURE;
+ }
+
const bool create_db = !glue_db_init_and_load();
#endif