mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-07 11:12:50 +01:00
Allow to optional specify the directory for the blocks storage
This commit is contained in:
33
src/util.cpp
33
src/util.cpp
@@ -598,10 +598,41 @@ 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)
|
||||
{
|
||||
|
||||
LOCK(csPathCached);
|
||||
|
||||
fs::path &path = fNetSpecific ? g_blocks_path_cache_net_specific : g_blocks_path_cached;
|
||||
|
||||
// This can be called during exceptions by LogPrintf(), so we cache the
|
||||
// value so we don't have to do memory allocations after that.
|
||||
if (!path.empty())
|
||||
return path;
|
||||
|
||||
if (gArgs.IsArgSet("-blocksdir")) {
|
||||
path = fs::system_complete(gArgs.GetArg("-blocksdir", ""));
|
||||
if (!fs::is_directory(path)) {
|
||||
path = "";
|
||||
return path;
|
||||
}
|
||||
} else {
|
||||
path = GetDataDir(false);
|
||||
}
|
||||
if (fNetSpecific)
|
||||
path /= BaseParams().DataDir();
|
||||
|
||||
path /= "blocks";
|
||||
fs::create_directories(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
const fs::path &GetDataDir(bool fNetSpecific)
|
||||
{
|
||||
|
||||
@@ -640,6 +671,8 @@ void ClearDatadirCache()
|
||||
|
||||
pathCached = fs::path();
|
||||
pathCachedNetSpecific = fs::path();
|
||||
g_blocks_path_cached = fs::path();
|
||||
g_blocks_path_cache_net_specific = fs::path();
|
||||
}
|
||||
|
||||
fs::path GetConfigFile(const std::string& confPath)
|
||||
|
||||
Reference in New Issue
Block a user