mirror of
https://github.com/XRPLF/rippled.git
synced 2026-10-21 02:58:27 +00:00
Compare commits
1 Commits
mvadari/re
...
bthomee/co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f95f7889f9 |
@@ -330,8 +330,21 @@ public:
|
|||||||
public:
|
public:
|
||||||
Config();
|
Config();
|
||||||
|
|
||||||
/* Be very careful to make sure these bool params
|
/**
|
||||||
are in the right order. */
|
* Set up the configuration and determine the config and data directories.
|
||||||
|
*
|
||||||
|
* When no config file is named, searches the working directory, then the XDG
|
||||||
|
* config directory when HOME is set, then the system config directory, and
|
||||||
|
* takes the first holding a config file under either name. The system config
|
||||||
|
* directory is the default when none does.
|
||||||
|
*
|
||||||
|
* Be very careful to make sure these bool params are in the right order.
|
||||||
|
*
|
||||||
|
* @param strConf Path of the config file, or empty to search for it.
|
||||||
|
* @param bQuiet Whether to minimize logging verbosity.
|
||||||
|
* @param bSilent Whether to write no console output after startup.
|
||||||
|
* @param bStandalone Whether to operate in stand-alone mode.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
setup(std::string const& strConf, bool bQuiet, bool bSilent, bool bStandalone);
|
setup(std::string const& strConf, bool bQuiet, bool bSilent, bool bStandalone);
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -319,59 +320,66 @@ Config::setup(std::string const& strConf, bool bQuiet, bool bSilent, bool bStand
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
do
|
// A config directory, paired with its data directory.
|
||||||
|
struct Candidate
|
||||||
{
|
{
|
||||||
// Check if either of the config files exist in the current working
|
std::filesystem::path configDir;
|
||||||
// directory, in which case the databases will be stored in a
|
std::filesystem::path dataDir;
|
||||||
// subdirectory.
|
};
|
||||||
configDir = std::filesystem::current_path();
|
|
||||||
dataDir = configDir / kDatabaseDirName;
|
|
||||||
configFile_ = configDir / kConfigFileName;
|
|
||||||
if (std::filesystem::exists(configFile_))
|
|
||||||
break;
|
|
||||||
configFile_ = configDir / kConfigLegacyName;
|
|
||||||
if (std::filesystem::exists(configFile_))
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Check if the home directory is set, and optionally the XDG config
|
// The candidates to search, in order.
|
||||||
// and/or data directories, as the config may be there. See
|
std::vector<Candidate> candidates;
|
||||||
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html.
|
candidates.reserve(3);
|
||||||
auto const strHome = getEnvVar("HOME");
|
|
||||||
if (!strHome.empty())
|
// The current working directory, with the databases in a subdirectory.
|
||||||
|
auto const cwd = std::filesystem::current_path();
|
||||||
|
candidates.emplace_back(cwd, cwd / kDatabaseDirName);
|
||||||
|
|
||||||
|
// The XDG config and data directories, which only apply when the home
|
||||||
|
// directory is set. See
|
||||||
|
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html.
|
||||||
|
if (auto const strHome = getEnvVar("HOME"); !strHome.empty())
|
||||||
|
{
|
||||||
|
auto strXdgConfigHome = getEnvVar("XDG_CONFIG_HOME");
|
||||||
|
if (strXdgConfigHome.empty())
|
||||||
{
|
{
|
||||||
auto strXdgConfigHome = getEnvVar("XDG_CONFIG_HOME");
|
// $XDG_CONFIG_HOME was not set, use default based on $HOME.
|
||||||
auto strXdgDataHome = getEnvVar("XDG_DATA_HOME");
|
strXdgConfigHome = strHome + "/.config";
|
||||||
if (strXdgConfigHome.empty())
|
}
|
||||||
{
|
auto strXdgDataHome = getEnvVar("XDG_DATA_HOME");
|
||||||
// $XDG_CONFIG_HOME was not set, use default based on $HOME.
|
if (strXdgDataHome.empty())
|
||||||
strXdgConfigHome = strHome + "/.config";
|
{
|
||||||
}
|
// $XDG_DATA_HOME was not set, use default based on $HOME.
|
||||||
if (strXdgDataHome.empty())
|
strXdgDataHome = strHome + "/.local/share";
|
||||||
{
|
}
|
||||||
// $XDG_DATA_HOME was not set, use default based on $HOME.
|
candidates.emplace_back(
|
||||||
strXdgDataHome = strHome + "/.local/share";
|
strXdgConfigHome + "/" + systemName(), strXdgDataHome + "/" + systemName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if either of the config files exist in the XDG config
|
// The system config directory, as a last resort.
|
||||||
// dir.
|
candidates.emplace_back("/etc/" + systemName(), "/var/lib/" + systemName());
|
||||||
dataDir = strXdgDataHome + "/" + systemName();
|
|
||||||
configDir = strXdgConfigHome + "/" + systemName();
|
// Take the first candidate holding a config file under either name.
|
||||||
configFile_ = configDir / kConfigFileName;
|
// When none does, the last candidate's values stand.
|
||||||
if (std::filesystem::exists(configFile_))
|
for (auto const& candidate : candidates)
|
||||||
break;
|
{
|
||||||
configFile_ = configDir / kConfigLegacyName;
|
configDir = candidate.configDir;
|
||||||
|
dataDir = candidate.dataDir;
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
for (std::string_view const fileName : {kConfigFileName, kConfigLegacyName})
|
||||||
|
{
|
||||||
|
configFile_ = configDir / fileName;
|
||||||
if (std::filesystem::exists(configFile_))
|
if (std::filesystem::exists(configFile_))
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// As a last resort, check the system config directory.
|
if (found)
|
||||||
dataDir = "/var/lib/" + systemName();
|
|
||||||
configDir = "/etc/" + systemName();
|
|
||||||
configFile_ = configDir / kConfigFileName;
|
|
||||||
if (std::filesystem::exists(configFile_))
|
|
||||||
break;
|
break;
|
||||||
configFile_ = configDir / kConfigLegacyName;
|
}
|
||||||
} while (false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update default values
|
// Update default values
|
||||||
|
|||||||
Reference in New Issue
Block a user