From 716de29dd8672d28bfe0a08424e9958fe61054d2 Mon Sep 17 00:00:00 2001 From: Kiminuo Date: Thu, 20 May 2021 22:28:06 +0200 Subject: Make `m_cached_blocks_path` mutable. Make `ArgsManager::GetBlocksDirPath()` const. --- src/util/system.cpp | 2 +- src/util/system.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/util') diff --git a/src/util/system.cpp b/src/util/system.cpp index 9b3bd46b38..06684c78ad 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -388,7 +388,7 @@ std::optional ArgsManager::GetArgFlags(const std::string& name) co return std::nullopt; } -const fs::path& ArgsManager::GetBlocksDirPath() +const fs::path& ArgsManager::GetBlocksDirPath() const { LOCK(cs_args); fs::path& path = m_cached_blocks_path; diff --git a/src/util/system.h b/src/util/system.h index f68975ffa3..88a217f71d 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -195,7 +195,7 @@ protected: std::map> m_available_args GUARDED_BY(cs_args); bool m_accept_any_command GUARDED_BY(cs_args){true}; std::list m_config_sections GUARDED_BY(cs_args); - fs::path m_cached_blocks_path GUARDED_BY(cs_args); + mutable 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,7 +266,7 @@ public: * * @return Blocks path which is network specific */ - const fs::path& GetBlocksDirPath(); + const fs::path& GetBlocksDirPath() const; /** * Get data directory path -- cgit v1.2.3 From 0f53df47d5b8319fc71f3b87c15a115ff797fb50 Mon Sep 17 00:00:00 2001 From: Kiminuo Date: Sat, 22 May 2021 14:55:38 +0200 Subject: Add `ArgsManager.GetDataDirBase()` and `ArgsManager.GetDataDirNet()` as an intended replacement for `ArgsManager.GetDataDirPath(net_identifier)` --- src/util/system.cpp | 8 ++++---- src/util/system.h | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'src/util') diff --git a/src/util/system.cpp b/src/util/system.cpp index 06684c78ad..3613d780ca 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -404,7 +404,7 @@ const fs::path& ArgsManager::GetBlocksDirPath() const return path; } } else { - path = GetDataDirPath(false); + path = GetDataDirBase(); } path /= BaseParams().DataDir(); @@ -513,7 +513,7 @@ bool ArgsManager::GetSettingsPath(fs::path* filepath, bool temp) const } if (filepath) { std::string settings = GetArg("-settings", BITCOIN_SETTINGS_FILENAME); - *filepath = fsbridge::AbsPathJoin(GetDataDirPath(/* net_specific= */ true), temp ? settings + ".tmp" : settings); + *filepath = fsbridge::AbsPathJoin(GetDataDirNet(), temp ? settings + ".tmp" : settings); } return true; } @@ -804,7 +804,7 @@ fs::path GetDefaultDataDir() const fs::path &GetDataDir(bool fNetSpecific) { - return gArgs.GetDataDirPath(fNetSpecific); + return fNetSpecific ? gArgs.GetDataDirNet() : gArgs.GetDataDirBase(); } bool CheckDataDirOption() @@ -1361,7 +1361,7 @@ fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific) if (path.is_absolute()) { return path; } - return fsbridge::AbsPathJoin(GetDataDir(net_specific), path); + return fsbridge::AbsPathJoin(net_specific ? gArgs.GetDataDirNet() : gArgs.GetDataDirBase(), path); } void ScheduleBatchPriority() diff --git a/src/util/system.h b/src/util/system.h index 88a217f71d..fcbbd24e83 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -119,7 +119,7 @@ UniValue RunCommandParseJSON(const std::string& str_command, const std::string& * the datadir if they are not absolute. * * @param path The path to be conditionally prefixed with datadir. - * @param net_specific Forwarded to GetDataDir(). + * @param net_specific Use network specific datadir variant * @return The normalized path. */ fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific = true); @@ -268,6 +268,22 @@ public: */ const fs::path& GetBlocksDirPath() const; + /** + * Get data directory path + * + * @return Absolute path on success, otherwise an empty path when a non-directory path would be returned + * @post Returned directory path is created unless it is empty + */ + const fs::path& GetDataDirBase() const { return GetDataDirPath(false); } + + /** + * Get data directory path with appended network identifier + * + * @return Absolute path on success, otherwise an empty path when a non-directory path would be returned + * @post Returned directory path is created unless it is empty + */ + const fs::path& GetDataDirNet() const { return GetDataDirPath(true); } + /** * Get data directory path * -- cgit v1.2.3 From 13bd8bb0536f008118b1de921654925ed9ce1da7 Mon Sep 17 00:00:00 2001 From: Kiminuo Date: Sat, 22 May 2021 15:01:04 +0200 Subject: Make `ArgsManager.GetDataDirPath` private and drop needless suffix --- src/util/system.cpp | 2 +- src/util/system.h | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/util') diff --git a/src/util/system.cpp b/src/util/system.cpp index 3613d780ca..3dcf3e9b6e 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -414,7 +414,7 @@ const fs::path& ArgsManager::GetBlocksDirPath() const return path; } -const fs::path& ArgsManager::GetDataDirPath(bool net_specific) const +const fs::path& ArgsManager::GetDataDir(bool net_specific) const { LOCK(cs_args); fs::path& path = net_specific ? m_cached_network_datadir_path : m_cached_datadir_path; diff --git a/src/util/system.h b/src/util/system.h index fcbbd24e83..6a4bd9f99e 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -274,7 +274,7 @@ public: * @return Absolute path on success, otherwise an empty path when a non-directory path would be returned * @post Returned directory path is created unless it is empty */ - const fs::path& GetDataDirBase() const { return GetDataDirPath(false); } + const fs::path& GetDataDirBase() const { return GetDataDir(false); } /** * Get data directory path with appended network identifier @@ -282,16 +282,7 @@ public: * @return Absolute path on success, otherwise an empty path when a non-directory path would be returned * @post Returned directory path is created unless it is empty */ - const fs::path& GetDataDirNet() const { return GetDataDirPath(true); } - - /** - * Get data directory path - * - * @param net_specific Append network identifier to the returned path - * @return Absolute path on success, otherwise an empty path when a non-directory path would be returned - * @post Returned directory path is created unless it is empty - */ - const fs::path& GetDataDirPath(bool net_specific = true) const; + const fs::path& GetDataDirNet() const { return GetDataDir(true); } /** * Clear cached directory paths @@ -453,6 +444,15 @@ public: void LogArgs() const; private: + /** + * Get data directory path + * + * @param net_specific Append network identifier to the returned path + * @return Absolute path on success, otherwise an empty path when a non-directory path would be returned + * @post Returned directory path is created unless it is empty + */ + const fs::path& GetDataDir(bool net_specific) const; + // Helper function for LogArgs(). void logArgsPrefix( const std::string& prefix, -- cgit v1.2.3 From aca0e5dcdb174ef7e88b76910d6fffd633688235 Mon Sep 17 00:00:00 2001 From: Kiminuo Date: Tue, 4 May 2021 12:58:44 +0200 Subject: Remove `GetDataDir(bool fNetSpecific = true)` function --- src/util/system.cpp | 5 ----- src/util/system.h | 1 - 2 files changed, 6 deletions(-) (limited to 'src/util') diff --git a/src/util/system.cpp b/src/util/system.cpp index 3dcf3e9b6e..3f14a19a4a 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -802,11 +802,6 @@ fs::path GetDefaultDataDir() #endif } -const fs::path &GetDataDir(bool fNetSpecific) -{ - return fNetSpecific ? gArgs.GetDataDirNet() : gArgs.GetDataDirBase(); -} - bool CheckDataDirOption() { std::string datadir = gArgs.GetArg("-datadir", ""); diff --git a/src/util/system.h b/src/util/system.h index 6a4bd9f99e..c4317c62d0 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -90,7 +90,6 @@ void ReleaseDirectoryLocks(); bool TryCreateDirectories(const fs::path& p); fs::path GetDefaultDataDir(); -const fs::path &GetDataDir(bool fNetSpecific = true); // Return true if -datadir option points to a valid directory or is not specified. bool CheckDataDirOption(); fs::path GetConfigFile(const std::string& confPath); -- cgit v1.2.3