Skip to content

Commit 64c1054

Browse files
committed
util: make GetDataDir read-only & create datadir..
.. only in bitcoind and bitcoin-qt This changes behaviour of GetConfigFilePath which now always returns the absolute path of the provided -conf argument.
1 parent 56e370f commit 64c1054

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

src/qt/bitcoin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans
167167

168168
static bool InitSettings()
169169
{
170+
gArgs.EnsureDataDir();
170171
if (!gArgs.GetSettingsPath()) {
171172
return true; // Do nothing if settings file disabled.
172173
}

src/util/system.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,7 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const
417417
LOCK(cs_args);
418418
fs::path& path = net_specific ? m_cached_network_datadir_path : m_cached_datadir_path;
419419

420-
// Cache the path to avoid calling fs::create_directories on every call of
421-
// this function
420+
// Used cached path if available
422421
if (!path.empty()) return path;
423422

424423
const fs::path datadir{GetPathArg("-datadir")};
@@ -432,15 +431,8 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const
432431
path = GetDefaultDataDir();
433432
}
434433

435-
if (!fs::exists(path)) {
436-
fs::create_directories(path / "wallets");
437-
}
438-
439434
if (net_specific && !BaseParams().DataDir().empty()) {
440435
path /= fs::PathFromString(BaseParams().DataDir());
441-
if (!fs::exists(path)) {
442-
fs::create_directories(path / "wallets");
443-
}
444436
}
445437

446438
return path;
@@ -512,6 +504,7 @@ bool ArgsManager::IsArgSet(const std::string& strArg) const
512504

513505
bool ArgsManager::InitSettings(std::string& error)
514506
{
507+
EnsureDataDir();
515508
if (!GetSettingsPath()) {
516509
return true; // Do nothing if settings file disabled.
517510
}
@@ -999,8 +992,8 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
999992
m_config_sections.clear();
1000993
}
1001994

1002-
const fs::path conf_path = GetPathArg("-conf", BITCOIN_CONF_FILENAME);
1003-
std::ifstream stream{GetConfigFile(conf_path)};
995+
const auto conf_path{GetConfigFilePath()};
996+
std::ifstream stream{conf_path};
1004997

1005998
// not ok to have a config file specified that cannot be opened
1006999
if (IsArgSet("-conf") && !stream.good()) {

src/util/system.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ class ArgsManager
492492
*
493493
* @param net_specific Append network identifier to the returned path
494494
* @return Absolute path on success, otherwise an empty path when a non-directory path would be returned
495-
* @post Returned directory path is created unless it is empty
496495
*/
497496
const fs::path& GetDataDir(bool net_specific) const;
498497

0 commit comments

Comments
 (0)