Globals: Decouple GetConfigFile and ReadConfigFile from global mapArgs

This commit is contained in:
Jorge Timón 2016-09-28 10:10:15 +02:00
parent 7b784cc2bb
commit 3450c18a12
No known key found for this signature in database
GPG Key ID: 8866C18EA1C944A2
6 changed files with 12 additions and 11 deletions

View File

@ -92,7 +92,7 @@ static bool AppInitRPC(int argc, char* argv[])
return false;
}
try {
ReadConfigFile(mapArgs, mapMultiArgs);
ReadConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME), mapArgs, mapMultiArgs);
} catch (const std::exception& e) {
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;
@ -209,7 +209,7 @@ UniValue CallRPC(const string& strMethod, const UniValue& params)
if (!GetAuthCookie(&strRPCUserColonPass)) {
throw runtime_error(strprintf(
_("Could not locate RPC credentials. No authentication cookie could be found, and no rpcpassword is set in the configuration file (%s)"),
GetConfigFile().string().c_str()));
GetConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME)).string().c_str()));
}
} else {

View File

@ -104,7 +104,7 @@ bool AppInit(int argc, char* argv[])
}
try
{
ReadConfigFile(mapArgs, mapMultiArgs);
ReadConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME), mapArgs, mapMultiArgs);
} catch (const std::exception& e) {
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;

View File

@ -1064,7 +1064,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
LogPrintf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()));
LogPrintf("Default data directory %s\n", GetDefaultDataDir().string());
LogPrintf("Using data directory %s\n", strDataDir);
LogPrintf("Using config file %s\n", GetConfigFile().string());
LogPrintf("Using config file %s\n", GetConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME)).string());
LogPrintf("Using at most %i connections (%i file descriptors available)\n", nMaxConnections, nFD);
LogPrintf("Using %u threads for script verification\n", nScriptCheckThreads);

View File

@ -590,7 +590,7 @@ int main(int argc, char *argv[])
return 1;
}
try {
ReadConfigFile(mapArgs, mapMultiArgs);
ReadConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME), mapArgs, mapMultiArgs);
} catch (const std::exception& e) {
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
QObject::tr("Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what()));

View File

@ -518,19 +518,20 @@ void ClearDatadirCache()
pathCachedNetSpecific = boost::filesystem::path();
}
boost::filesystem::path GetConfigFile()
boost::filesystem::path GetConfigFile(const std::string& confPath)
{
boost::filesystem::path pathConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME));
boost::filesystem::path pathConfigFile(confPath);
if (!pathConfigFile.is_complete())
pathConfigFile = GetDataDir(false) / pathConfigFile;
return pathConfigFile;
}
void ReadConfigFile(map<string, string>& mapSettingsRet,
void ReadConfigFile(const std::string& confPath,
map<string, string>& mapSettingsRet,
map<string, vector<string> >& mapMultiSettingsRet)
{
boost::filesystem::ifstream streamConfig(GetConfigFile());
boost::filesystem::ifstream streamConfig(GetConfigFile(confPath));
if (!streamConfig.good())
return; // No bitcoin.conf file is OK

View File

@ -102,12 +102,12 @@ bool TryCreateDirectory(const boost::filesystem::path& p);
boost::filesystem::path GetDefaultDataDir();
const boost::filesystem::path &GetDataDir(bool fNetSpecific = true);
void ClearDatadirCache();
boost::filesystem::path GetConfigFile();
boost::filesystem::path GetConfigFile(const std::string& confPath);
#ifndef WIN32
boost::filesystem::path GetPidFile();
void CreatePidFile(const boost::filesystem::path &path, pid_t pid);
#endif
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
void ReadConfigFile(const std::string& confPath, std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
#ifdef WIN32
boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
#endif