diff options
author | Jonas Schnelli <dev@jonasschnelli.ch> | 2018-03-09 12:12:43 +0800 |
---|---|---|
committer | Jonas Schnelli <dev@jonasschnelli.ch> | 2018-03-11 12:37:20 +0800 |
commit | 386a6b62a8a1db9dd0f354cb95b7585f555c7e5d (patch) | |
tree | 4179dce98f66712dd2f266ed0568b8911cbf8831 /src/util.cpp | |
parent | ed6ae8059cdbad60466807a7cfb23e5540a50051 (diff) |
Allow to optional specify the directory for the blocks storage
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp index dcf7ed38b1..18a020ccd9 100644 --- a/src/util.cpp +++ b/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) |