mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Merge #14409: utils and libraries: Make 'blocksdir' always net specific
e4a0c3547eImprove blocksdir functional test. (Hennadii Stepanov)c3f1821ac7Make blockdir always net specific (Hennadii Stepanov) Pull request description: The blocks directory is net specific by definition. Also this prevents the side effect of calling `GetBlocksDir(false)` in the non-mainnet environment. Currently a new node creates an unused `blocks\` directory in the root of the data directory when `-testnet` or `-regtest` is specified. Refs: - #12653 - https://github.com/bitcoin/bitcoin/pull/12653#discussion_r174784834 by @laanwj - https://github.com/bitcoin/bitcoin/issues/14595#issuecomment-436011186 Tree-SHA512: c9957a68a4a200ebd2010823a56db7e61563afedcb7c9828e86b13f3af2990e07854b622c1f3374756f94574acb3ea32de7d2a399eef6c0623f0e11265155627
This commit is contained in:
@@ -749,18 +749,17 @@ fs::path GetDefaultDataDir()
|
||||
#endif
|
||||
}
|
||||
|
||||
static fs::path g_blocks_path_cached;
|
||||
static fs::path g_blocks_path_cache_net_specific;
|
||||
static fs::path pathCached;
|
||||
static fs::path pathCachedNetSpecific;
|
||||
static CCriticalSection csPathCached;
|
||||
|
||||
const fs::path &GetBlocksDir(bool fNetSpecific)
|
||||
const fs::path &GetBlocksDir()
|
||||
{
|
||||
|
||||
LOCK(csPathCached);
|
||||
|
||||
fs::path &path = fNetSpecific ? g_blocks_path_cache_net_specific : g_blocks_path_cached;
|
||||
fs::path &path = g_blocks_path_cache_net_specific;
|
||||
|
||||
// This can be called during exceptions by LogPrintf(), so we cache the
|
||||
// value so we don't have to do memory allocations after that.
|
||||
@@ -776,9 +775,8 @@ const fs::path &GetBlocksDir(bool fNetSpecific)
|
||||
} else {
|
||||
path = GetDataDir(false);
|
||||
}
|
||||
if (fNetSpecific)
|
||||
path /= BaseParams().DataDir();
|
||||
|
||||
path /= BaseParams().DataDir();
|
||||
path /= "blocks";
|
||||
fs::create_directories(path);
|
||||
return path;
|
||||
@@ -822,7 +820,6 @@ void ClearDatadirCache()
|
||||
|
||||
pathCached = fs::path();
|
||||
pathCachedNetSpecific = fs::path();
|
||||
g_blocks_path_cached = fs::path();
|
||||
g_blocks_path_cache_net_specific = fs::path();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user