mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
Merge f4cfa6d019 into merged_master (Bitcoin PR #15935)
This commit is contained in:
commit
e377f4f773
14 changed files with 404 additions and 6 deletions
|
|
@ -79,6 +79,7 @@ const char * const BITCOIN_PID_FILENAME = "liquid.pid";
|
|||
const char * const BITCOIN_CONF_FILENAME = "elements.conf";
|
||||
const char * const BITCOIN_PID_FILENAME = "elementsd.pid";
|
||||
#endif
|
||||
const char * const BITCOIN_SETTINGS_FILENAME = "settings.json";
|
||||
|
||||
ArgsManager gArgs;
|
||||
|
||||
|
|
@ -363,6 +364,84 @@ bool ArgsManager::IsArgSet(const std::string& strArg) const
|
|||
return !GetSetting(strArg).isNull();
|
||||
}
|
||||
|
||||
bool ArgsManager::InitSettings(std::string& error)
|
||||
{
|
||||
if (!GetSettingsPath()) {
|
||||
return true; // Do nothing if settings file disabled.
|
||||
}
|
||||
|
||||
std::vector<std::string> errors;
|
||||
if (!ReadSettingsFile(&errors)) {
|
||||
error = strprintf("Failed loading settings file:\n- %s\n", Join(errors, "\n- "));
|
||||
return false;
|
||||
}
|
||||
if (!WriteSettingsFile(&errors)) {
|
||||
error = strprintf("Failed saving settings file:\n- %s\n", Join(errors, "\n- "));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArgsManager::GetSettingsPath(fs::path* filepath, bool temp) const
|
||||
{
|
||||
if (IsArgNegated("-settings")) {
|
||||
return false;
|
||||
}
|
||||
if (filepath) {
|
||||
std::string settings = GetArg("-settings", BITCOIN_SETTINGS_FILENAME);
|
||||
*filepath = fs::absolute(temp ? settings + ".tmp" : settings, GetDataDir(/* net_specific= */ true));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void SaveErrors(const std::vector<std::string> errors, std::vector<std::string>* error_out)
|
||||
{
|
||||
for (const auto& error : errors) {
|
||||
if (error_out) {
|
||||
error_out->emplace_back(error);
|
||||
} else {
|
||||
LogPrintf("%s\n", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ArgsManager::ReadSettingsFile(std::vector<std::string>* errors)
|
||||
{
|
||||
fs::path path;
|
||||
if (!GetSettingsPath(&path, /* temp= */ false)) {
|
||||
return true; // Do nothing if settings file disabled.
|
||||
}
|
||||
|
||||
LOCK(cs_args);
|
||||
m_settings.rw_settings.clear();
|
||||
std::vector<std::string> read_errors;
|
||||
if (!util::ReadSettings(path, m_settings.rw_settings, read_errors)) {
|
||||
SaveErrors(read_errors, errors);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors) const
|
||||
{
|
||||
fs::path path, path_tmp;
|
||||
if (!GetSettingsPath(&path, /* temp= */ false) || !GetSettingsPath(&path_tmp, /* temp= */ true)) {
|
||||
throw std::logic_error("Attempt to write settings file when dynamic settings are disabled.");
|
||||
}
|
||||
|
||||
LOCK(cs_args);
|
||||
std::vector<std::string> write_errors;
|
||||
if (!util::WriteSettings(path_tmp, m_settings.rw_settings, write_errors)) {
|
||||
SaveErrors(write_errors, errors);
|
||||
return false;
|
||||
}
|
||||
if (!RenameOver(path_tmp, path)) {
|
||||
SaveErrors({strprintf("Failed renaming settings file %s to %s\n", path_tmp.string(), path.string())}, errors);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArgsManager::IsArgNegated(const std::string& strArg) const
|
||||
{
|
||||
return GetSetting(strArg).isFalse();
|
||||
|
|
@ -917,6 +996,9 @@ void ArgsManager::LogArgs() const
|
|||
for (const auto& section : m_settings.ro_config) {
|
||||
logArgsPrefix("Config file arg:", section.first, section.second);
|
||||
}
|
||||
for (const auto& setting : m_settings.rw_settings) {
|
||||
LogPrintf("Setting file arg: %s = %s\n", setting.first, setting.second.write());
|
||||
}
|
||||
logArgsPrefix("Command-line arg:", "", m_settings.command_line_options);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue