diff options
author | Andrew Chow <github@achow101.com> | 2023-02-28 10:49:55 -0500 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-02-28 11:01:21 -0500 |
commit | 8303f11e106807ea82938b2f3878b33daedb3d3f (patch) | |
tree | 88b24211935e0e89c4ddf5e2e4e3da9311daee27 /src/util | |
parent | 9384536eb302a12361781caf86fab545bb97044e (diff) | |
parent | 9a9d5da11fa6033f82dcf8e2298aee29587f5396 (diff) |
Merge bitcoin/bitcoin#27170: refactor: Stop using gArgs global in system.cpp
9a9d5da11fa6033f82dcf8e2298aee29587f5396 refactor: Stop using gArgs global in system.cpp (Ryan Ofsky)
b20b34f5b33230fe253c81008496bd9b13fd6ecf refactor: 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:
ACK 9a9d5da11fa6033f82dcf8e2298aee29587f5396
stickies-v:
ACK 9a9d5da11
willcl-ark:
tACK 9a9d5da11
Tree-SHA512: 2c74b0d5fc83e9ed2ec6562eb26ec735512f75db8876a11a5d5f04e6cdbe0cd8beec19894091aa2cbf29319194d2429ccbf8036f5520ecc394f6fe89a0079a7b
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/system.cpp | 20 | ||||
-rw-r--r-- | src/util/system.h | 8 |
2 files changed, 15 insertions, 13 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp index 77b659df7e..58afd264ae 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -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() diff --git a/src/util/system.h b/src/util/system.h index cb3d76ece5..3eb0a0f2b8 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -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) { |