Skip to content

Commit 1276090

Browse files
committed
util, refactor: Use GetPathArg to read "-conf" value
Also "includeconf" values been normalized.
1 parent 1c6fcea commit 1276090

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, co
801801
if (failedToGetAuthCookie) {
802802
throw std::runtime_error(strprintf(
803803
"Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set. See -rpcpassword and -stdinrpcpass. Configuration file: (%s)",
804-
fs::PathToString(GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)))));
804+
fs::PathToString(GetConfigFile(gArgs.GetPathArg("-conf", BITCOIN_CONF_FILENAME)))));
805805
} else {
806806
throw std::runtime_error("Authorization failed: Incorrect rpcuser or rpcpassword");
807807
}

src/init/common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bool StartLogging(const ArgsManager& args)
137137
LogPrintf("Using data directory %s\n", fs::PathToString(gArgs.GetDataDirNet()));
138138

139139
// Only log conf file usage message if conf file actually exists.
140-
fs::path config_file_path = GetConfigFile(args.GetArg("-conf", BITCOIN_CONF_FILENAME));
140+
fs::path config_file_path = GetConfigFile(args.GetPathArg("-conf", BITCOIN_CONF_FILENAME));
141141
if (fs::exists(config_file_path)) {
142142
LogPrintf("Config file: %s\n", fs::PathToString(config_file_path));
143143
} else if (args.IsArgSet("-conf")) {

src/qt/guiutil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ void openDebugLogfile()
431431

432432
bool openBitcoinConf()
433433
{
434-
fs::path pathConfig = GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));
434+
fs::path pathConfig = GetConfigFile(gArgs.GetPathArg("-conf", BITCOIN_CONF_FILENAME));
435435

436436
/* Create the file */
437437
std::ofstream configFile{pathConfig, std::ios_base::app};

src/util/system.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,9 @@ bool CheckDataDirOption()
826826
return datadir.empty() || fs::is_directory(fs::absolute(datadir));
827827
}
828828

829-
fs::path GetConfigFile(const std::string& confPath)
829+
fs::path GetConfigFile(const fs::path& configuration_file_path)
830830
{
831-
return AbsPathForConfigVal(fs::PathFromString(confPath), false);
831+
return AbsPathForConfigVal(configuration_file_path, /*net_specific=*/false);
832832
}
833833

834834
static bool GetConfigOptions(std::istream& stream, const std::string& filepath, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo>& sections)
@@ -912,17 +912,17 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
912912
m_config_sections.clear();
913913
}
914914

915-
const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME);
916-
std::ifstream stream{GetConfigFile(confPath)};
915+
const fs::path conf_path = GetPathArg("-conf", BITCOIN_CONF_FILENAME);
916+
std::ifstream stream{GetConfigFile(conf_path)};
917917

918918
// not ok to have a config file specified that cannot be opened
919919
if (IsArgSet("-conf") && !stream.good()) {
920-
error = strprintf("specified config file \"%s\" could not be opened.", confPath);
920+
error = strprintf("specified config file \"%s\" could not be opened.", fs::PathToString(conf_path));
921921
return false;
922922
}
923923
// ok to not have a config file
924924
if (stream.good()) {
925-
if (!ReadConfigStream(stream, confPath, error, ignore_invalid_keys)) {
925+
if (!ReadConfigStream(stream, fs::PathToString(conf_path), error, ignore_invalid_keys)) {
926926
return false;
927927
}
928928
// `-includeconf` cannot be included in the command line arguments except
@@ -960,7 +960,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
960960
const size_t default_includes = add_includes({});
961961

962962
for (const std::string& conf_file_name : conf_file_names) {
963-
std::ifstream conf_file_stream{GetConfigFile(conf_file_name)};
963+
std::ifstream conf_file_stream{GetConfigFile(fs::PathFromString(conf_file_name))};
964964
if (conf_file_stream.good()) {
965965
if (!ReadConfigStream(conf_file_stream, conf_file_name, error, ignore_invalid_keys)) {
966966
return false;

src/util/system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool TryCreateDirectories(const fs::path& p);
9898
fs::path GetDefaultDataDir();
9999
// Return true if -datadir option points to a valid directory or is not specified.
100100
bool CheckDataDirOption();
101-
fs::path GetConfigFile(const std::string& confPath);
101+
fs::path GetConfigFile(const fs::path& configuration_file_path);
102102
#ifdef WIN32
103103
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
104104
#endif

0 commit comments

Comments
 (0)