Use ArgsManager::GetPathArg() for "-datadir" option

This commit is contained in:
Hennadii Stepanov 2022-02-04 18:23:50 +02:00
parent 540ca5111f
commit 15b632bf16
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
2 changed files with 5 additions and 5 deletions

View File

@ -1150,7 +1150,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD); LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD);
// Warn about relative -datadir path. // Warn about relative -datadir path.
if (args.IsArgSet("-datadir") && !fs::PathFromString(args.GetArg("-datadir", "")).is_absolute()) { if (args.IsArgSet("-datadir") && !args.GetPathArg("-datadir").is_absolute()) {
LogPrintf("Warning: relative datadir option '%s' specified, which will be interpreted relative to the " /* Continued */ LogPrintf("Warning: relative datadir option '%s' specified, which will be interpreted relative to the " /* Continued */
"current working directory '%s'. This is fragile, because if bitcoin is started in the future " "current working directory '%s'. This is fragile, because if bitcoin is started in the future "
"from a different location, it will be unable to locate the current data files. There could " "from a different location, it will be unable to locate the current data files. There could "

View File

@ -440,9 +440,9 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const
// this function // this function
if (!path.empty()) return path; if (!path.empty()) return path;
std::string datadir = GetArg("-datadir", ""); const fs::path datadir{GetPathArg("-datadir")};
if (!datadir.empty()) { if (!datadir.empty()) {
path = fs::absolute(StripRedundantLastElementsOfPath(fs::PathFromString(datadir))); path = fs::absolute(datadir);
if (!fs::is_directory(path)) { if (!fs::is_directory(path)) {
path = ""; path = "";
return path; return path;
@ -823,8 +823,8 @@ fs::path GetDefaultDataDir()
bool CheckDataDirOption() bool CheckDataDirOption()
{ {
std::string datadir = gArgs.GetArg("-datadir", ""); const fs::path datadir{gArgs.GetPathArg("-datadir")};
return datadir.empty() || fs::is_directory(fs::absolute(fs::PathFromString(datadir))); return datadir.empty() || fs::is_directory(fs::absolute(datadir));
} }
fs::path GetConfigFile(const std::string& confPath) fs::path GetConfigFile(const std::string& confPath)