config/Path: add InitPathParser()

Eliminate yet another access to the global ConfigData instance.
This commit is contained in:
Max Kellermann 2018-08-19 22:29:39 +02:00
parent 1a9659ef45
commit 5f95c07305
3 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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 <pwd.h>
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)
{

View File

@ -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.
*/