diff --git a/src/Main.cxx b/src/Main.cxx index 53162b33b..50d496f44 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -55,6 +55,7 @@ #include "config/Global.hxx" #include "config/Data.hxx" #include "config/Param.hxx" +#include "config/Path.hxx" #include "config/Defaults.hxx" #include "config/Option.hxx" #include "config/Domain.hxx" @@ -491,6 +492,7 @@ MainOrThrow(int argc, char *argv[]) #endif const auto &raw_config = GetGlobalConfig(); + InitPathParser(raw_config); const auto config = LoadConfig(raw_config); #ifdef ENABLE_DAEMON diff --git a/src/config/Path.cxx b/src/config/Path.cxx index 9775adf73..432cae0ef 100644 --- a/src/config/Path.cxx +++ b/src/config/Path.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2017 The Music Player Daemon Project + * Copyright 2003-2018 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,7 +19,7 @@ #include "config.h" #include "Path.hxx" -#include "Global.hxx" +#include "Data.hxx" #include "fs/AllocatedPath.hxx" #include "fs/Traits.hxx" #include "fs/Domain.hxx" @@ -32,6 +32,8 @@ #ifndef _WIN32 #include +static const char *configured_user = nullptr; + /** * Determine a given user's home directory. */ @@ -66,14 +68,23 @@ GetHome() static AllocatedPath GetConfiguredHome() { - const char *user = config_get_string(ConfigOption::USER); - return user != nullptr - ? GetHome(user) + return configured_user != nullptr + ? GetHome(configured_user) : GetHome(); } #endif +void +InitPathParser(const ConfigData &config) noexcept +{ +#ifdef _WIN32 + (void)config; +#else + configured_user = config.GetString(ConfigOption::USER); +#endif +} + AllocatedPath ParsePath(const char *path) { diff --git a/src/config/Path.hxx b/src/config/Path.hxx index 2bc952680..d178d097a 100644 --- a/src/config/Path.hxx +++ b/src/config/Path.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2017 The Music Player Daemon Project + * Copyright 2003-2018 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -20,8 +20,12 @@ #ifndef MPD_CONFIG_PATH_HXX #define MPD_CONFIG_PATH_HXX +struct ConfigData; class AllocatedPath; +void +InitPathParser(const ConfigData &config) noexcept; + /** * Throws #std::runtime_error on error. */