diff options
author | willcl-ark <will@256k1.dev> | 2023-02-09 14:42:02 +0000 |
---|---|---|
committer | willcl-ark <will@256k1.dev> | 2023-02-23 08:37:27 +0000 |
commit | 56e370fbb9413260723c598048392219b1055ad0 (patch) | |
tree | 66439b2ee44aef3cab3c9d4772a76c4afefe5725 /src/util | |
parent | 2c1fe27bf3c1e504864987cbe80f9c24897d3cb1 (diff) |
util: add ArgsManager datadir helper functions
* Add ArgsManager::EnsureDataDir()
Creates data directory if it doesn't exist
* Add ArgsManager::GetConfigFilePath()
Return config file path (read-only)
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/system.cpp | 26 | ||||
-rw-r--r-- | src/util/system.h | 11 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp index e72c970157..d104d0d3f8 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -446,6 +446,27 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const return path; } +void ArgsManager::EnsureDataDir() const +{ + /** + * "/wallets" subdirectories are created in all **new** + * datadirs, because wallet code will create new wallets in the "wallets" + * subdirectory only if exists already, otherwise it will create them in + * the top-level datadir where they could interfere with other files. + * Wallet init code currently avoids creating "wallets" directories itself + * for backwards compatibility, but this be changed in the future and + * wallet code here could go away (#16220). + */ + auto path{GetDataDir(false)}; + if (!fs::exists(path)) { + fs::create_directories(path / "wallets"); + } + path = GetDataDir(true); + if (!fs::exists(path)) { + fs::create_directories(path / "wallets"); + } +} + void ArgsManager::ClearPathCache() { LOCK(cs_args); @@ -965,6 +986,11 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file return true; } +fs::path ArgsManager::GetConfigFilePath() const +{ + return GetConfigFile(GetPathArg("-conf", BITCOIN_CONF_FILENAME)); +} + bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) { { diff --git a/src/util/system.h b/src/util/system.h index c053adf8c3..49fcd751fc 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -242,6 +242,11 @@ protected: void SelectConfigNetwork(const std::string& network); [[nodiscard]] bool ParseParameters(int argc, const char* const argv[], std::string& error); + + /** + * Return config file path (read-only) + */ + fs::path GetConfigFilePath() const; [[nodiscard]] bool ReadConfigFiles(std::string& error, bool ignore_invalid_keys = false); /** @@ -475,6 +480,12 @@ protected: */ void LogArgs() const; + /** + * If datadir does not exist, create it along with wallets/ + * subdirectory(s). + */ + void EnsureDataDir() const; + private: /** * Get data directory path |