Skip to content

Commit e09ad28

Browse files
committed
Merge bitcoin/bitcoin#24675: util: Use ArgsManager::GetPathArg more widely
b01f336 util, refactor: Drop explicit conversion to fs::path (Hennadii Stepanov) 138c668 util, refactor: Use GetPathArg to read "-rpccookiefile" value (Hennadii Stepanov) 1276090 util, refactor: Use GetPathArg to read "-conf" value (Hennadii Stepanov) Pull request description: This PR is a continuation of bitcoin/bitcoin#24265 and bitcoin/bitcoin#24306. Now the following command-line arguments / configure options been read with the `GetPathArg` method: - `-conf`, also `includeconf` values been normalized - `-rpccookiefile` ACKs for top commit: jarolrod: Code Review ACK b01f336 ryanofsky: Code review ACK b01f336. Changes since last review: just dropping first commit (NormalizedPathFromString) as suggested Tree-SHA512: 2d26d50b73542acdbcc63a32068977b2a49a017d31ca337471a0446f964eb0a6e3e4e3bb1ebe6771566a260f2cae3bc2ebe93b4b523183cea0d51768daab85c9
2 parents 36c83b4 + b01f336 commit e09ad28

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

src/bitcoin-cli.cpp

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

src/init/common.cpp

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

101101
// Only log conf file usage message if conf file actually exists.
102-
fs::path config_file_path = GetConfigFile(args.GetArg("-conf", BITCOIN_CONF_FILENAME));
102+
fs::path config_file_path = GetConfigFile(args.GetPathArg("-conf", BITCOIN_CONF_FILENAME));
103103
if (fs::exists(config_file_path)) {
104104
LogPrintf("Config file: %s\n", fs::PathToString(config_file_path));
105105
} else if (args.IsArgSet("-conf")) {

src/qt/guiutil.cpp

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

429429
bool openBitcoinConf()
430430
{
431-
fs::path pathConfig = GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));
431+
fs::path pathConfig = GetConfigFile(gArgs.GetPathArg("-conf", BITCOIN_CONF_FILENAME));
432432

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

src/rpc/request.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ UniValue JSONRPCError(int code, const std::string& message)
6666
*/
6767
static const std::string COOKIEAUTH_USER = "__cookie__";
6868
/** Default name for auth cookie file */
69-
static const std::string COOKIEAUTH_FILE = ".cookie";
69+
static const char* const COOKIEAUTH_FILE = ".cookie";
7070

7171
/** Get name of RPC authentication cookie file */
7272
static fs::path GetAuthCookieFile(bool temp=false)
7373
{
74-
std::string arg = gArgs.GetArg("-rpccookiefile", COOKIEAUTH_FILE);
74+
fs::path arg = gArgs.GetPathArg("-rpccookiefile", COOKIEAUTH_FILE);
7575
if (temp) {
7676
arg += ".tmp";
7777
}
78-
return AbsPathForConfigVal(fs::PathFromString(arg));
78+
return AbsPathForConfigVal(arg);
7979
}
8080

8181
bool GenerateAuthCookie(std::string *cookie_out)

src/util/system.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ bool ArgsManager::InitSettings(std::string& error)
522522

523523
bool ArgsManager::GetSettingsPath(fs::path* filepath, bool temp, bool backup) const
524524
{
525-
fs::path settings = GetPathArg("-settings", fs::path{BITCOIN_SETTINGS_FILENAME});
525+
fs::path settings = GetPathArg("-settings", BITCOIN_SETTINGS_FILENAME);
526526
if (settings.empty()) {
527527
return false;
528528
}
@@ -885,9 +885,9 @@ bool CheckDataDirOption()
885885
return datadir.empty() || fs::is_directory(fs::absolute(datadir));
886886
}
887887

888-
fs::path GetConfigFile(const std::string& confPath)
888+
fs::path GetConfigFile(const fs::path& configuration_file_path)
889889
{
890-
return AbsPathForConfigVal(fs::PathFromString(confPath), false);
890+
return AbsPathForConfigVal(configuration_file_path, /*net_specific=*/false);
891891
}
892892

893893
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)
@@ -971,17 +971,17 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
971971
m_config_sections.clear();
972972
}
973973

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

977977
// not ok to have a config file specified that cannot be opened
978978
if (IsArgSet("-conf") && !stream.good()) {
979-
error = strprintf("specified config file \"%s\" could not be opened.", confPath);
979+
error = strprintf("specified config file \"%s\" could not be opened.", fs::PathToString(conf_path));
980980
return false;
981981
}
982982
// ok to not have a config file
983983
if (stream.good()) {
984-
if (!ReadConfigStream(stream, confPath, error, ignore_invalid_keys)) {
984+
if (!ReadConfigStream(stream, fs::PathToString(conf_path), error, ignore_invalid_keys)) {
985985
return false;
986986
}
987987
// `-includeconf` cannot be included in the command line arguments except
@@ -1019,7 +1019,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
10191019
const size_t default_includes = add_includes({});
10201020

10211021
for (const std::string& conf_file_name : conf_file_names) {
1022-
std::ifstream conf_file_stream{GetConfigFile(conf_file_name)};
1022+
std::ifstream conf_file_stream{GetConfigFile(fs::PathFromString(conf_file_name))};
10231023
if (conf_file_stream.good()) {
10241024
if (!ReadConfigStream(conf_file_stream, conf_file_name, error, ignore_invalid_keys)) {
10251025
return false;

src/util/system.h

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

0 commit comments

Comments
 (0)