Separate out ReadConfigStream from ReadConfigFile

This commit is contained in:
Anthony Towns 2018-03-29 15:02:00 +10:00
parent 834d303415
commit 6d5815aad0
2 changed files with 12 additions and 4 deletions

View file

@ -735,10 +735,9 @@ fs::path GetConfigFile(const std::string& confPath)
return AbsPathForConfigVal(fs::path(confPath), false);
}
void ArgsManager::ReadConfigFile(const std::string& confPath)
void ArgsManager::ReadConfigStream(std::istream& stream)
{
fs::ifstream streamConfig(GetConfigFile(confPath));
if (!streamConfig.good())
if (!stream.good())
return; // No bitcoin.conf file is OK
{
@ -746,7 +745,7 @@ void ArgsManager::ReadConfigFile(const std::string& confPath)
std::set<std::string> setOptions;
setOptions.insert("*");
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
for (boost::program_options::detail::config_file_iterator it(stream, setOptions), end; it != end; ++it)
{
// Don't overwrite existing settings so command line settings override bitcoin.conf
std::string strKey = std::string("-") + it->string_key;
@ -757,6 +756,13 @@ void ArgsManager::ReadConfigFile(const std::string& confPath)
mapMultiArgs[strKey].push_back(strValue);
}
}
}
void ArgsManager::ReadConfigFile(const std::string& confPath)
{
fs::ifstream stream(GetConfigFile(confPath));
ReadConfigStream(stream);
// If datadir is changed in .conf file:
ClearDatadirCache();
if (!fs::is_directory(GetDataDir(false))) {

View file

@ -228,6 +228,8 @@ protected:
std::map<std::string, std::vector<std::string>> mapMultiArgs;
std::unordered_set<std::string> m_negated_args;
void ReadConfigStream(std::istream& stream);
public:
void ParseParameters(int argc, const char*const argv[]);
void ReadConfigFile(const std::string& confPath);