mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-07 06:07:32 +02:00
Merge bitcoin/bitcoin#21850: Remove GetDataDir(net_specific) function
aca0e5dcdbRemove `GetDataDir(bool fNetSpecific = true)` function (Kiminuo)b3e67f20a0scripted-diff: Replace `GetDataDir(true)` calls with `gArgs.GetDataDirNet()` calls (Kiminuo)4c3a5dcbfcscripted-diff: Replace `GetDataDir()` calls with `gArgs.GetDataDirNet()` calls (Kiminuo)13bd8bb053Make `ArgsManager.GetDataDirPath` private and drop needless suffix (Kiminuo)4d8189f620scripted-diff: Change `ArgsManager.GetDataDirPath()` to `ArgsManager.GetDataDirBase()` in tests (Kiminuo)0f53df47d5Add `ArgsManager.GetDataDirBase()` and `ArgsManager.GetDataDirNet()` as an intended replacement for `ArgsManager.GetDataDirPath(net_identifier)` (Kiminuo)716de29dd8Make `m_cached_blocks_path` mutable. Make `ArgsManager::GetBlocksDirPath()` const. (Kiminuo) Pull request description: This PR is a follow up PR to #21244. The PR attempts to move us an inch towards the [goal](https://github.com/bitcoin/bitcoin/pull/21244#discussion_r615307465) by removing `GetDataDir(net_specific)` and replacing it by `gArgs.GetDataDir(net_specific)` calls. The approach of this PR attempts to be similar to the one chosen in "De-globalize ChainstateManager" (#20158). The goal is to pass `ArgsManager` to functions (or ideally to have `ArgsManager` as a member of a class where needed; inspiration from here: #21789) instead of having it as a global variable (i.e. `gArgs`). **Notes:** * First commit makes `m_cached_blocks_path` `mutable` as was suggested [here](https://github.com/bitcoin/bitcoin/pull/21244#discussion_r615274095) but not fully applied in #21244. (`m_cached_datadir_path` and `m_cached_network_datadir_path` were marked as `mutable` in #21244) This commit can be in a separate PR too. * Other commits deal with removing of `GetDataDir(net_specific)` function. * This was originally part of #21244 but it was [left]((https://github.com/bitcoin/bitcoin/pull/21244#pullrequestreview-633779754)) for a follow up PR. * I think that the proposed changes show nicely where there is reliance on `gArgs` which is IMO a good thing. If you know about a better approach how to do this, please share it here. ACKs for top commit: hebasto: ACKaca0e5dcdbMarcoFalke: re-ACKaca0e5dcdb👃 Tree-SHA512: deec4d88edb32d7f4c818c3a74ffbb64709685819b88242dcf5dbaa1fb611f3ce2b29d2576ddb9e0dc5e75288e43538968224008c0a80e7149fc81c309f7c9da
This commit is contained in:
@@ -386,7 +386,7 @@ std::optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) co
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const fs::path& ArgsManager::GetBlocksDirPath()
|
||||
const fs::path& ArgsManager::GetBlocksDirPath() const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
fs::path& path = m_cached_blocks_path;
|
||||
@@ -402,7 +402,7 @@ const fs::path& ArgsManager::GetBlocksDirPath()
|
||||
return path;
|
||||
}
|
||||
} else {
|
||||
path = GetDataDirPath(false);
|
||||
path = GetDataDirBase();
|
||||
}
|
||||
|
||||
path /= BaseParams().DataDir();
|
||||
@@ -412,7 +412,7 @@ const fs::path& ArgsManager::GetBlocksDirPath()
|
||||
return path;
|
||||
}
|
||||
|
||||
const fs::path& ArgsManager::GetDataDirPath(bool net_specific) const
|
||||
const fs::path& ArgsManager::GetDataDir(bool net_specific) const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
fs::path& path = net_specific ? m_cached_network_datadir_path : m_cached_datadir_path;
|
||||
@@ -511,7 +511,7 @@ bool ArgsManager::GetSettingsPath(fs::path* filepath, bool temp) const
|
||||
}
|
||||
if (filepath) {
|
||||
std::string settings = GetArg("-settings", BITCOIN_SETTINGS_FILENAME);
|
||||
*filepath = fsbridge::AbsPathJoin(GetDataDirPath(/* net_specific= */ true), temp ? settings + ".tmp" : settings);
|
||||
*filepath = fsbridge::AbsPathJoin(GetDataDirNet(), temp ? settings + ".tmp" : settings);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -800,11 +800,6 @@ fs::path GetDefaultDataDir()
|
||||
#endif
|
||||
}
|
||||
|
||||
const fs::path &GetDataDir(bool fNetSpecific)
|
||||
{
|
||||
return gArgs.GetDataDirPath(fNetSpecific);
|
||||
}
|
||||
|
||||
bool CheckDataDirOption()
|
||||
{
|
||||
std::string datadir = gArgs.GetArg("-datadir", "");
|
||||
@@ -1359,7 +1354,7 @@ fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
|
||||
if (path.is_absolute()) {
|
||||
return path;
|
||||
}
|
||||
return fsbridge::AbsPathJoin(GetDataDir(net_specific), path);
|
||||
return fsbridge::AbsPathJoin(net_specific ? gArgs.GetDataDirNet() : gArgs.GetDataDirBase(), path);
|
||||
}
|
||||
|
||||
void ScheduleBatchPriority()
|
||||
|
||||
Reference in New Issue
Block a user