mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 09:43:55 +02:00
Merge bitcoin/bitcoin#27170: refactor: Stop using gArgs global in system.cpp
9a9d5da11frefactor: Stop using gArgs global in system.cpp (Ryan Ofsky)b20b34f5b3refactor: Use new GetConfigFilePath function (Ryan Ofsky) Pull request description: Most of the code in `util/system.cpp` that was hardcoded to use the global `ArgsManager` instance `gArgs` has been changed to stop using it (for example in https://github.com/bitcoin/bitcoin/pull/20092). But a few hardcoded references to `gArgs` remain. This commit removes the last ones so these functions aren't reading or writing global state. Noticed these `gArgs` references while reviewing #27073 ACKs for top commit: achow101: ACK9a9d5da11fstickies-v: ACK9a9d5da11willcl-ark: tACK9a9d5da11Tree-SHA512: 2c74b0d5fc83e9ed2ec6562eb26ec735512f75db8876a11a5d5f04e6cdbe0cd8beec19894091aa2cbf29319194d2429ccbf8036f5520ecc394f6fe89a0079a7b
This commit is contained in:
@@ -880,15 +880,15 @@ fs::path GetDefaultDataDir()
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CheckDataDirOption()
|
||||
bool CheckDataDirOption(const ArgsManager& args)
|
||||
{
|
||||
const fs::path datadir{gArgs.GetPathArg("-datadir")};
|
||||
const fs::path datadir{args.GetPathArg("-datadir")};
|
||||
return datadir.empty() || fs::is_directory(fs::absolute(datadir));
|
||||
}
|
||||
|
||||
fs::path GetConfigFile(const fs::path& configuration_file_path)
|
||||
fs::path GetConfigFile(const ArgsManager& args, const fs::path& configuration_file_path)
|
||||
{
|
||||
return AbsPathForConfigVal(configuration_file_path, /*net_specific=*/false);
|
||||
return AbsPathForConfigVal(args, configuration_file_path, /*net_specific=*/false);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -981,7 +981,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
|
||||
|
||||
fs::path ArgsManager::GetConfigFilePath() const
|
||||
{
|
||||
return GetConfigFile(GetPathArg("-conf", BITCOIN_CONF_FILENAME));
|
||||
return GetConfigFile(*this, GetPathArg("-conf", BITCOIN_CONF_FILENAME));
|
||||
}
|
||||
|
||||
bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
|
||||
@@ -1040,7 +1040,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
|
||||
const size_t default_includes = add_includes({});
|
||||
|
||||
for (const std::string& conf_file_name : conf_file_names) {
|
||||
std::ifstream conf_file_stream{GetConfigFile(fs::PathFromString(conf_file_name))};
|
||||
std::ifstream conf_file_stream{GetConfigFile(*this, fs::PathFromString(conf_file_name))};
|
||||
if (conf_file_stream.good()) {
|
||||
if (!ReadConfigStream(conf_file_stream, conf_file_name, error, ignore_invalid_keys)) {
|
||||
return false;
|
||||
@@ -1068,8 +1068,8 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
|
||||
}
|
||||
|
||||
// If datadir is changed in .conf file:
|
||||
gArgs.ClearPathCache();
|
||||
if (!CheckDataDirOption()) {
|
||||
ClearPathCache();
|
||||
if (!CheckDataDirOption(*this)) {
|
||||
error = strprintf("specified data directory \"%s\" does not exist.", GetArg("-datadir", ""));
|
||||
return false;
|
||||
}
|
||||
@@ -1409,12 +1409,12 @@ int64_t GetStartupTime()
|
||||
return nStartupTime;
|
||||
}
|
||||
|
||||
fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
|
||||
fs::path AbsPathForConfigVal(const ArgsManager& args, const fs::path& path, bool net_specific)
|
||||
{
|
||||
if (path.is_absolute()) {
|
||||
return path;
|
||||
}
|
||||
return fsbridge::AbsPathJoin(net_specific ? gArgs.GetDataDirNet() : gArgs.GetDataDirBase(), path);
|
||||
return fsbridge::AbsPathJoin(net_specific ? args.GetDataDirNet() : args.GetDataDirBase(), path);
|
||||
}
|
||||
|
||||
void ScheduleBatchPriority()
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class ArgsManager;
|
||||
class UniValue;
|
||||
|
||||
// Application startup time (used for uptime calculation)
|
||||
@@ -96,8 +97,8 @@ void ReleaseDirectoryLocks();
|
||||
bool TryCreateDirectories(const fs::path& p);
|
||||
fs::path GetDefaultDataDir();
|
||||
// Return true if -datadir option points to a valid directory or is not specified.
|
||||
bool CheckDataDirOption();
|
||||
fs::path GetConfigFile(const fs::path& configuration_file_path);
|
||||
bool CheckDataDirOption(const ArgsManager& args);
|
||||
fs::path GetConfigFile(const ArgsManager& args, const fs::path& configuration_file_path);
|
||||
#ifdef WIN32
|
||||
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
|
||||
#endif
|
||||
@@ -112,11 +113,12 @@ void runCommand(const std::string& strCommand);
|
||||
* Most paths passed as configuration arguments are treated as relative to
|
||||
* the datadir if they are not absolute.
|
||||
*
|
||||
* @param args Parsed arguments and settings.
|
||||
* @param path The path to be conditionally prefixed with datadir.
|
||||
* @param net_specific Use network specific datadir variant
|
||||
* @return The normalized path.
|
||||
*/
|
||||
fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific = true);
|
||||
fs::path AbsPathForConfigVal(const ArgsManager& args, const fs::path& path, bool net_specific = true);
|
||||
|
||||
inline bool IsSwitchChar(char c)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user