Changeset View
Changeset View
Standalone View
Standalone View
src/util.cpp
Show First 20 Lines • Show All 464 Lines • ▼ Show 20 Lines | #endif | ||||
// Check for -nofoo | // Check for -nofoo | ||||
if (InterpretNegatedOption(key, val)) { | if (InterpretNegatedOption(key, val)) { | ||||
m_override_args[key].clear(); | m_override_args[key].clear(); | ||||
} else { | } else { | ||||
m_override_args[key].push_back(val); | m_override_args[key].push_back(val); | ||||
} | } | ||||
} | } | ||||
// we do not allow -includeconf from command line, so we clear it here | |||||
auto it = m_override_args.find("-includeconf"); | |||||
if (it != m_override_args.end()) { | |||||
if (it->second.size() > 0) { | |||||
for (const auto &ic : it->second) { | |||||
fprintf(stderr, | |||||
"warning: -includeconf cannot be used from " | |||||
"commandline; ignoring -includeconf=%s\n", | |||||
ic.c_str()); | |||||
} | |||||
m_override_args.erase(it); | |||||
} | |||||
} | |||||
} | } | ||||
std::vector<std::string> ArgsManager::GetArgs(const std::string &strArg) const { | std::vector<std::string> ArgsManager::GetArgs(const std::string &strArg) const { | ||||
std::vector<std::string> result = {}; | std::vector<std::string> result = {}; | ||||
// special case | // special case | ||||
if (IsArgNegated(strArg)) { | if (IsArgNegated(strArg)) { | ||||
return result; | return result; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | for (boost::program_options::detail::config_file_iterator | ||||
if (InterpretNegatedOption(strKey, strValue)) { | if (InterpretNegatedOption(strKey, strValue)) { | ||||
m_config_args[strKey].clear(); | m_config_args[strKey].clear(); | ||||
} else { | } else { | ||||
m_config_args[strKey].push_back(strValue); | m_config_args[strKey].push_back(strValue); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void ArgsManager::ReadConfigFile(const std::string &confPath) { | void ArgsManager::ReadConfigFiles() { | ||||
{ | { | ||||
LOCK(cs_args); | LOCK(cs_args); | ||||
m_config_args.clear(); | m_config_args.clear(); | ||||
} | } | ||||
const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME); | |||||
fs::ifstream stream(GetConfigFile(confPath)); | fs::ifstream stream(GetConfigFile(confPath)); | ||||
// ok to not have a config file | // ok to not have a config file | ||||
if (stream.good()) { | if (stream.good()) { | ||||
ReadConfigStream(stream); | ReadConfigStream(stream); | ||||
// if there is an -includeconf in the override args, but it is empty, | |||||
// that means the user passed '-noincludeconf' on the command line, in | |||||
// which case we should not include anything | |||||
bool emptyIncludeConf; | |||||
{ | |||||
LOCK(cs_args); | |||||
emptyIncludeConf = m_override_args.count("-includeconf") == 0; | |||||
} | |||||
if (emptyIncludeConf) { | |||||
std::vector<std::string> includeconf(GetArgs("-includeconf")); | |||||
{ | |||||
// We haven't set m_network yet (that happens in | |||||
// SelectParams()), so manually check for network.includeconf | |||||
// args. | |||||
std::vector<std::string> includeconf_net(GetArgs( | |||||
std::string("-") + GetChainName() + ".includeconf")); | |||||
includeconf.insert(includeconf.end(), includeconf_net.begin(), | |||||
includeconf_net.end()); | |||||
} | |||||
for (const std::string &to_include : includeconf) { | |||||
fs::ifstream include_config(GetConfigFile(to_include)); | |||||
if (include_config.good()) { | |||||
ReadConfigStream(include_config); | |||||
LogPrintf("Included configuration file %s\n", | |||||
to_include.c_str()); | |||||
} else { | |||||
fprintf(stderr, "Failed to include configuration file %s\n", | |||||
to_include.c_str()); | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
// If datadir is changed in .conf file: | // If datadir is changed in .conf file: | ||||
ClearDatadirCache(); | ClearDatadirCache(); | ||||
if (!fs::is_directory(GetDataDir(false))) { | if (!fs::is_directory(GetDataDir(false))) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
strprintf("specified data directory \"%s\" does not exist.", | strprintf("specified data directory \"%s\" does not exist.", | ||||
gArgs.GetArg("-datadir", "").c_str())); | gArgs.GetArg("-datadir", "").c_str())); | ||||
▲ Show 20 Lines • Show All 263 Lines • Show Last 20 Lines |