I did some digging, and I think (would be nice to get more confirmation on this) we can scrap the net_specific == false
version entirely, we don’t seem to need it. EnsureDataDir
is called 3 times: 2 times right before reading config files - but it looks like we don’t actually need to ensure a datadir there. If datadir doesn’t exist, by definition no config files can be read (and that’s handled gracefully). The only time we need it is where net_specific==true
.
Intuitively, this makes sense - it can never hurt to ensure that all the necessary datadirs (both base as well as the more specific net) exist. However, there actually is a pitfall, because GetDataDir()
does some caching, we’re not allowed to call GetDatDir(true)
before we’ve determined the network we’re on (which requires us to first read the basedir and check if there’s a config file there).
For that reason, I think calling it EnsureDataDirNet
is probably better - and aligns with GetDataDirNet
naming.
0diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
1index 3a36ff700..07002cc8a 100644
2--- a/src/bitcoind.cpp
3+++ b/src/bitcoind.cpp
4@@ -153,7 +153,6 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
5 if (!CheckDataDirOption()) {
6 return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""))));
7 }
8- args.EnsureDataDir(/*net_specific=*/false);
9 if (!args.ReadConfigFiles(error, true)) {
10 return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error)));
11 }
12diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
13index 80e607f77..59f433749 100644
14--- a/src/qt/bitcoin.cpp
15+++ b/src/qt/bitcoin.cpp
16@@ -596,7 +596,6 @@ int GuiMain(int argc, char* argv[])
17 try {
18 /// 6b. Parse bitcoin.conf
19 /// - Do not call gArgs.GetDataDirNet() before this step finishes
20- gArgs.EnsureDataDir(/*net_specific=*/false);
21 if (!gArgs.ReadConfigFiles(error, true)) {
22 InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
23 QMessageBox::critical(nullptr, PACKAGE_NAME,
24diff --git a/src/util/system.cpp b/src/util/system.cpp
25index 329100008..75fd91516 100644
26--- a/src/util/system.cpp
27+++ b/src/util/system.cpp
28@@ -439,9 +439,9 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const
29 return path;
30 }
31
32-void ArgsManager::EnsureDataDir(bool net_specific)
33+void ArgsManager::EnsureDataDirNet()
34 {
35- fs::path path = GetDataDir(net_specific);
36+ fs::path path = GetDataDir(true);
37 if (!fs::exists(path)) {
38 fs::create_directories(path / "wallets");
39 }
40@@ -492,7 +492,7 @@ bool ArgsManager::IsArgSet(const std::string& strArg) const
41
42 bool ArgsManager::InitSettings(std::string& error)
43 {
44- EnsureDataDir(/*net_specific=*/true);
45+ EnsureDataDirNet();
46 if (!GetSettingsPath()) {
47 return true; // Do nothing if settings file disabled.
48 }
49diff --git a/src/util/system.h b/src/util/system.h
50index 3bcbd5c8e..23c15228e 100644
51--- a/src/util/system.h
52+++ b/src/util/system.h
53@@ -478,10 +478,8 @@ protected:
54
55 /**
56 * Create data directory if it doesn't exist
57- *
58- * [@param](/bitcoin-bitcoin/contributor/param/) net_specific Create a network-identified data directory
59 */
60- void EnsureDataDir(bool net_specific);
61+ void EnsureDataDirNet();
62
63 private:
64 /**