From d765182bbb460614d107b13cff9c71240c23b64a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 2 Nov 2016 10:01:29 +0100 Subject: [PATCH] config/Global: _get_path() throws exception on error --- src/Main.cxx | 62 ++++++++++--------------------------- src/config/ConfigGlobal.cxx | 5 ++- src/config/ConfigGlobal.hxx | 8 ++--- src/storage/Configured.cxx | 10 ++---- 4 files changed, 25 insertions(+), 60 deletions(-) diff --git a/src/Main.cxx b/src/Main.cxx index 243a7f275..0d421777b 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -129,34 +129,23 @@ Instance *instance; #ifdef ENABLE_DAEMON -static bool -glue_daemonize_init(const struct options *options, Error &error) +static void +glue_daemonize_init(const struct options *options) { - auto pid_file = config_get_path(ConfigOption::PID_FILE, error); - if (pid_file.IsNull() && error.IsDefined()) - return false; - daemonize_init(config_get_string(ConfigOption::USER, nullptr), config_get_string(ConfigOption::GROUP, nullptr), - std::move(pid_file)); + config_get_path(ConfigOption::PID_FILE)); if (options->kill) daemonize_kill(); - - return true; } #endif -static bool -glue_mapper_init(Error &error) +static void +glue_mapper_init() { - auto playlist_dir = config_get_path(ConfigOption::PLAYLIST_DIR, error); - if (playlist_dir.IsNull() && error.IsDefined()) - return false; - - mapper_init(std::move(playlist_dir)); - return true; + mapper_init(config_get_path(ConfigOption::PLAYLIST_DIR)); } #ifdef ENABLE_DATABASE @@ -232,37 +221,30 @@ InitDatabaseAndStorage() * Configure and initialize the sticker subsystem. */ static void -glue_sticker_init(void) +glue_sticker_init() { #ifdef ENABLE_SQLITE - Error error; - auto sticker_file = config_get_path(ConfigOption::STICKER_FILE, error); - if (sticker_file.IsNull()) { - if (error.IsDefined()) - FatalError(error); + auto sticker_file = config_get_path(ConfigOption::STICKER_FILE); + if (sticker_file.IsNull()) return; - } sticker_global_init(std::move(sticker_file)); #endif } -static bool -glue_state_file_init(Error &error) +static void +glue_state_file_init() { - auto path_fs = config_get_path(ConfigOption::STATE_FILE, error); + auto path_fs = config_get_path(ConfigOption::STATE_FILE); if (path_fs.IsNull()) { - if (error.IsDefined()) - return false; - #ifdef ANDROID const auto cache_dir = GetUserCacheDir(); if (cache_dir.IsNull()) - return true; + return; path_fs = AllocatedPath::Build(cache_dir, "state"); #else - return true; + return; #endif } @@ -274,7 +256,6 @@ glue_state_file_init(Error &error) *instance->partition, instance->event_loop); instance->state_file->Read(); - return true; } /** @@ -425,10 +406,7 @@ try { #endif #ifdef ENABLE_DAEMON - if (!glue_daemonize_init(&options, error)) { - LogError(error); - return EXIT_FAILURE; - } + glue_daemonize_init(&options); #endif stats_global_init(); @@ -490,10 +468,7 @@ try { ConfigureFS(); - if (!glue_mapper_init(error)) { - LogError(error); - return EXIT_FAILURE; - } + glue_mapper_init(); initPermissions(); spl_global_init(); @@ -551,10 +526,7 @@ try { } #endif - if (!glue_state_file_init(error)) { - LogError(error); - return EXIT_FAILURE; - } + glue_state_file_init(); instance->partition->outputs.SetReplayGainMode(replay_gain_get_real_mode(instance->partition->playlist.queue.random)); diff --git a/src/config/ConfigGlobal.cxx b/src/config/ConfigGlobal.cxx index 017354d14..e382aacfc 100644 --- a/src/config/ConfigGlobal.cxx +++ b/src/config/ConfigGlobal.cxx @@ -28,7 +28,6 @@ #include "ConfigError.hxx" #include "fs/Path.hxx" #include "fs/AllocatedPath.hxx" -#include "util/Error.hxx" #include "system/FatalError.hxx" #include "Log.hxx" @@ -122,13 +121,13 @@ config_get_string(ConfigOption option, const char *default_value) } AllocatedPath -config_get_path(ConfigOption option, Error &error) +config_get_path(ConfigOption option) { const auto *param = config_get_param(option); if (param == nullptr) return AllocatedPath::Null(); - return param->GetPath(error); + return param->GetPath(); } unsigned diff --git a/src/config/ConfigGlobal.hxx b/src/config/ConfigGlobal.hxx index bd64452fc..ca846be27 100644 --- a/src/config/ConfigGlobal.hxx +++ b/src/config/ConfigGlobal.hxx @@ -23,7 +23,6 @@ #include "ConfigOption.hxx" #include "Compiler.h" -class Error; class Path; class AllocatedPath; struct ConfigParam; @@ -78,11 +77,12 @@ config_get_string(enum ConfigOption option, const char *default_value=nullptr); /** * Returns an optional configuration variable which contains an * absolute path. If there is a tilde prefix, it is expanded. - * Returns AllocatedPath::Null() if the value is not present. If the path - * could not be parsed, returns AllocatedPath::Null() and sets the error. + * Returns AllocatedPath::Null() if the value is not present. + * + * Throws #std::runtime_error on error. */ AllocatedPath -config_get_path(enum ConfigOption option, Error &error); +config_get_path(enum ConfigOption option); gcc_pure unsigned diff --git a/src/storage/Configured.cxx b/src/storage/Configured.cxx index 82e7cd603..e41f05cc9 100644 --- a/src/storage/Configured.cxx +++ b/src/storage/Configured.cxx @@ -26,7 +26,6 @@ #include "fs/StandardDirectory.hxx" #include "fs/CheckFile.hxx" #include "util/UriUtil.hxx" -#include "util/Error.hxx" #include "util/RuntimeError.hxx" #include @@ -44,14 +43,9 @@ CreateConfiguredStorageUri(EventLoop &event_loop, const char *uri) static AllocatedPath GetConfiguredMusicDirectory() { - Error error; - AllocatedPath path = config_get_path(ConfigOption::MUSIC_DIR, error); - if (path.IsNull()) { - if (error.IsDefined()) - throw std::runtime_error(error.GetMessage()); - + AllocatedPath path = config_get_path(ConfigOption::MUSIC_DIR); + if (path.IsNull()) path = GetUserMusicDir(); - } return path; }