Commit 5f95c073 authored by Max Kellermann's avatar Max Kellermann

config/Path: add InitPathParser()

Eliminate yet another access to the global ConfigData instance.
parent 1a9659ef
......@@ -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
......
/*
* 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)
{
......
/*
* 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.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment