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);
// 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 */
"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 "

View file

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