diff options
author | Max Kellermann <max@duempel.org> | 2014-02-07 23:37:39 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-07 23:37:39 +0100 |
commit | b0b086d47302867291f2241880b54429f0347691 (patch) | |
tree | 1290775ada0f1e3970a128719d40494afb77aa87 /src | |
parent | 6798af52b69a9c6712f79989349a5fce929cd874 (diff) | |
download | mpd-b0b086d47302867291f2241880b54429f0347691.tar.gz mpd-b0b086d47302867291f2241880b54429f0347691.tar.xz mpd-b0b086d47302867291f2241880b54429f0347691.zip |
Main: move storage initialization to InitStorage()
Diffstat (limited to '')
-rw-r--r-- | src/Main.cxx | 47 |
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 |