aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorKiminuo <kiminuo@protonmail.com>2021-04-09 08:16:36 +0200
committerKiminuo <kiminuo@protonmail.com>2021-04-18 11:59:28 +0200
commitb4190eff72c00e384ad238f9c2f10c8b91be969b (patch)
tree473640c5390ae891d1fb237b28dd351b9101f49f /src/util
parent83292e2a700afbf39936bd67bb89fab5398d0066 (diff)
Change GetBlocksDir() to ArgsManager.GetBlocksDirPath().
Diffstat (limited to 'src/util')
-rw-r--r--src/util/system.cpp57
-rw-r--r--src/util/system.h10
2 files changed, 35 insertions, 32 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 0a2ece7b10..474c4893f9 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -388,6 +388,32 @@ std::optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) co
return std::nullopt;
}
+const fs::path& ArgsManager::GetBlocksDirPath()
+{
+ LOCK(cs_args);
+ fs::path& path = m_cached_blocks_path;
+
+ // Cache the path to avoid calling fs::create_directories on every call of
+ // this function
+ if (!path.empty()) return path;
+
+ if (IsArgSet("-blocksdir")) {
+ path = fs::system_complete(GetArg("-blocksdir", ""));
+ if (!fs::is_directory(path)) {
+ path = "";
+ return path;
+ }
+ } else {
+ path = GetDataDirPath(false);
+ }
+
+ path /= BaseParams().DataDir();
+ path /= "blocks";
+ fs::create_directories(path);
+ path = StripRedundantLastElementsOfPath(path);
+ return path;
+}
+
const fs::path& ArgsManager::GetDataDirPath(bool net_specific) const
{
LOCK(cs_args);
@@ -425,6 +451,7 @@ void ArgsManager::ClearDatadirPathCache()
m_cached_datadir_path = fs::path();
m_cached_network_datadir_path = fs::path();
+ m_cached_blocks_path = fs::path();
}
std::optional<const ArgsManager::Command> ArgsManager::GetCommand() const
@@ -775,35 +802,6 @@ fs::path GetDefaultDataDir()
#endif
}
-static fs::path g_blocks_path_cache_net_specific;
-static RecursiveMutex csPathCached;
-
-const fs::path &GetBlocksDir()
-{
- LOCK(csPathCached);
- fs::path &path = g_blocks_path_cache_net_specific;
-
- // Cache the path to avoid calling fs::create_directories on every call of
- // this function
- 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);
- }
-
- path /= BaseParams().DataDir();
- path /= "blocks";
- fs::create_directories(path);
- path = StripRedundantLastElementsOfPath(path);
- return path;
-}
-
const fs::path &GetDataDir(bool fNetSpecific)
{
return gArgs.GetDataDirPath(fNetSpecific);
@@ -818,7 +816,6 @@ bool CheckDataDirOption()
void ClearDatadirCache()
{
gArgs.ClearDatadirPathCache();
- g_blocks_path_cache_net_specific = fs::path();
}
fs::path GetConfigFile(const std::string& confPath)
diff --git a/src/util/system.h b/src/util/system.h
index a49055b891..fcdb04bb8d 100644
--- a/src/util/system.h
+++ b/src/util/system.h
@@ -91,8 +91,6 @@ void ReleaseDirectoryLocks();
bool TryCreateDirectories(const fs::path& p);
fs::path GetDefaultDataDir();
-// The blocks directory is always net specific.
-const fs::path &GetBlocksDir();
const fs::path &GetDataDir(bool fNetSpecific = true);
// Return true if -datadir option points to a valid directory or is not specified.
bool CheckDataDirOption();
@@ -200,6 +198,7 @@ protected:
std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args GUARDED_BY(cs_args);
bool m_accept_any_command GUARDED_BY(cs_args){true};
std::list<SectionInfo> m_config_sections GUARDED_BY(cs_args);
+ fs::path m_cached_blocks_path GUARDED_BY(cs_args);
mutable fs::path m_cached_datadir_path GUARDED_BY(cs_args);
mutable fs::path m_cached_network_datadir_path GUARDED_BY(cs_args);
@@ -266,6 +265,13 @@ public:
std::optional<const Command> GetCommand() const;
/**
+ * Get blocks directory path
+ *
+ * @return Blocks path which is network specific
+ */
+ const fs::path& GetBlocksDirPath();
+
+ /**
* Get data directory path
*
* @param net_specific Append network identifier to the returned path