Skip to content

Commit

Permalink
Make blockdir always net specific
Browse files Browse the repository at this point in the history
The blocks directory is net specific by definition.

Also this prevents the side effect of calling GetBlocksDir(false) in the
non-mainnet environment.
  • Loading branch information
hebasto committed Nov 5, 2018
1 parent 13d98ea commit c3f1821
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ bool AppInitParameterInteraction()

// also see: InitParameterInteraction()

if (!fs::is_directory(GetBlocksDir(false))) {
if (!fs::is_directory(GetBlocksDir())) {
return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), gArgs.GetArg("-blocksdir", "").c_str()));
}

Expand Down
9 changes: 3 additions & 6 deletions src/util/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,18 +728,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.
Expand All @@ -755,9 +754,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;
Expand Down Expand Up @@ -801,7 +799,6 @@ void ClearDatadirCache()

pathCached = fs::path();
pathCachedNetSpecific = fs::path();
g_blocks_path_cached = fs::path();
g_blocks_path_cache_net_specific = fs::path();
}

Expand Down
3 changes: 2 additions & 1 deletion src/util/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ void ReleaseDirectoryLocks();

bool TryCreateDirectories(const fs::path& p);
fs::path GetDefaultDataDir();
const fs::path &GetBlocksDir(bool fNetSpecific = true);
// The blocks directory is always net specific.
const fs::path &GetBlocksDir();
const fs::path &GetDataDir(bool fNetSpecific = true);
void ClearDatadirCache();
fs::path GetConfigFile(const std::string& confPath);
Expand Down

0 comments on commit c3f1821

Please sign in to comment.