Merge #21244: Move GetDataDir to ArgsManager

bb8d1c6e02 Change ClearDataDirPathCache() to ArgsManager.ClearPathCache(). (Kiminuo)
b4190eff72 Change GetBlocksDir() to ArgsManager.GetBlocksDirPath(). (Kiminuo)
83292e2a70 scripted-diff: Modify unit tests to use the ArgsManager in the BasicTestingSetup class instead of implicitly relying on gArgs. (Kiminuo)
55c68e6f01 scripted-diff: Replace m_args with m_local_args in getarg_tests.cpp (Kiminuo)
511ce3a26b BasicTestingSetup: Add ArgsManager. (Kiminuo)
1cb52ba065 Modify "util_datadir" unit test to not use gArgs. (Kiminuo)
1add318704 Move GetDataDir(fNetSpecific) implementation to ArgsManager. (Kiminuo)
70cdf679f8 Move StripRedundantLastElementsOfPath before ArgsManager class. (Kiminuo)

Pull request description:

  This PR attempts to contribute to "Remove gArgs" (#21005).

  Main changes:

  * `GetDataDir()` function is moved to `ArgsManager.GetDataDirPath()`.
  * `GetBlocksDir()` function is moved to `ArgsManager.GetBlocksDirPath()`.

ACKs for top commit:
  ryanofsky:
    Code review ACK bb8d1c6e02. Just minor const/naming changes and splitting/scripting commits since last review
  MarcoFalke:
    review ACK bb8d1c6e02 📓
  hebasto:
    re-ACK bb8d1c6e02, addressed comments, and two commits made scripted-diffs since my [previous](https://github.com/bitcoin/bitcoin/pull/21244#pullrequestreview-638270583) review.

Tree-SHA512: ba9408c22129d6572beaa103dca0324131766f06d562bb7d6b9e214a0a4d40b0216ce861384562bde24b744003b3fbe6fac239061c8fd798abd3981ebc1b9019
This commit is contained in:
fanquake committed 2021-04-20 08:42:56 +08:00
commit a839303edc
14 files changed
+222 -193

No files matched your search

+4 -4
View File
@@ -637,7 +637,7 @@ static void CleanupBlockRevFiles()
// Remove the rev files immediately and insert the blk file paths into an // Remove the rev files immediately and insert the blk file paths into an
// ordered map keyed by block file index. // ordered map keyed by block file index.
LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n"); LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n");
fs::path blocksdir = GetBlocksDir(); fs::path blocksdir = gArgs.GetBlocksDirPath();
for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) { for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) {
if (fs::is_regular_file(*it) && if (fs::is_regular_file(*it) &&
it->path().filename().string().length() == 12 && it->path().filename().string().length() == 12 &&
@@ -919,7 +919,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
InitWarning(warnings); InitWarning(warnings);
} }
if (!fs::is_directory(GetBlocksDir())) { if (!fs::is_directory(gArgs.GetBlocksDirPath())) {
return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), args.GetArg("-blocksdir", ""))); return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), args.GetArg("-blocksdir", "")));
} }
@@ -1759,8 +1759,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
InitError(strprintf(_("Error: Disk space is low for %s"), GetDataDir())); InitError(strprintf(_("Error: Disk space is low for %s"), GetDataDir()));
return false; return false;
} }
if (!CheckDiskSpace(GetBlocksDir())) { if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) {
InitError(strprintf(_("Error: Disk space is low for %s"), GetBlocksDir())); InitError(strprintf(_("Error: Disk space is low for %s"), gArgs.GetBlocksDirPath()));
return false; return false;
} }
+1 -1
View File
@@ -216,7 +216,7 @@ QString ClientModel::dataDir() const
QString ClientModel::blocksDir() const QString ClientModel::blocksDir() const
{ {
return GUIUtil::boostPathToQString(GetBlocksDir()); return GUIUtil::boostPathToQString(gArgs.GetBlocksDirPath());
} }
void ClientModel::updateBanlist() void ClientModel::updateBanlist()
+9 -9
View File
@@ -26,7 +26,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper)
{ {
// Perform tests both obfuscated and non-obfuscated. // Perform tests both obfuscated and non-obfuscated.
for (const bool obfuscate : {false, true}) { for (const bool obfuscate : {false, true}) {
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_obfuscate_true" : "dbwrapper_obfuscate_false"); fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_obfuscate_true" : "dbwrapper_obfuscate_false");
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
char key = 'k'; char key = 'k';
uint256 in = InsecureRand256(); uint256 in = InsecureRand256();
@@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_basic_data)
{ {
// Perform tests both obfuscated and non-obfuscated. // Perform tests both obfuscated and non-obfuscated.
for (bool obfuscate : {false, true}) { for (bool obfuscate : {false, true}) {
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_1_obfuscate_true" : "dbwrapper_1_obfuscate_false"); fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_1_obfuscate_true" : "dbwrapper_1_obfuscate_false");
CDBWrapper dbw(ph, (1 << 20), false, true, obfuscate); CDBWrapper dbw(ph, (1 << 20), false, true, obfuscate);
uint256 res; uint256 res;
@@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_batch)
{ {
// Perform tests both obfuscated and non-obfuscated. // Perform tests both obfuscated and non-obfuscated.
for (const bool obfuscate : {false, true}) { for (const bool obfuscate : {false, true}) {
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_batch_obfuscate_true" : "dbwrapper_batch_obfuscate_false"); fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_batch_obfuscate_true" : "dbwrapper_batch_obfuscate_false");
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
char key = 'i'; char key = 'i';
@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
{ {
// Perform tests both obfuscated and non-obfuscated. // Perform tests both obfuscated and non-obfuscated.
for (const bool obfuscate : {false, true}) { for (const bool obfuscate : {false, true}) {
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_iterator_obfuscate_true" : "dbwrapper_iterator_obfuscate_false"); fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_iterator_obfuscate_true" : "dbwrapper_iterator_obfuscate_false");
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate); CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
// The two keys are intentionally chosen for ordering // The two keys are intentionally chosen for ordering
@@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
{ {
// We're going to share this fs::path between two wrappers // We're going to share this fs::path between two wrappers
fs::path ph = GetDataDir() / "existing_data_no_obfuscate"; fs::path ph = m_args.GetDataDirPath() / "existing_data_no_obfuscate";
create_directories(ph); create_directories(ph);
// Set up a non-obfuscated wrapper to write some initial data. // Set up a non-obfuscated wrapper to write some initial data.
@@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
BOOST_AUTO_TEST_CASE(existing_data_reindex) BOOST_AUTO_TEST_CASE(existing_data_reindex)
{ {
// We're going to share this fs::path between two wrappers // We're going to share this fs::path between two wrappers
fs::path ph = GetDataDir() / "existing_data_reindex"; fs::path ph = m_args.GetDataDirPath() / "existing_data_reindex";
create_directories(ph); create_directories(ph);
// Set up a non-obfuscated wrapper to write some initial data. // Set up a non-obfuscated wrapper to write some initial data.
@@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
BOOST_AUTO_TEST_CASE(iterator_ordering) BOOST_AUTO_TEST_CASE(iterator_ordering)
{ {
fs::path ph = GetDataDir() / "iterator_ordering"; fs::path ph = m_args.GetDataDirPath() / "iterator_ordering";
CDBWrapper dbw(ph, (1 << 20), true, false, false); CDBWrapper dbw(ph, (1 << 20), true, false, false);
for (int x=0x00; x<256; ++x) { for (int x=0x00; x<256; ++x) {
uint8_t key = x; uint8_t key = x;
@@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
{ {
char buf[10]; char buf[10];
fs::path ph = GetDataDir() / "iterator_string_ordering"; fs::path ph = m_args.GetDataDirPath() / "iterator_string_ordering";
CDBWrapper dbw(ph, (1 << 20), true, false, false); CDBWrapper dbw(ph, (1 << 20), true, false, false);
for (int x=0x00; x<10; ++x) { for (int x=0x00; x<10; ++x) {
for (int y = 0; y < 10; y++) { for (int y = 0; y < 10; y++) {
@@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(unicodepath)
// On Windows this test will fail if the directory is created using // On Windows this test will fail if the directory is created using
// the ANSI CreateDirectoryA call and the code page isn't UTF8. // the ANSI CreateDirectoryA call and the code page isn't UTF8.
// It will succeed if created with CreateDirectoryW. // It will succeed if created with CreateDirectoryW.
fs::path ph = GetDataDir() / "test_runner_₿_🏃_20191128_104644"; fs::path ph = m_args.GetDataDirPath() / "test_runner_₿_🏃_20191128_104644";
CDBWrapper dbw(ph, (1 << 20)); CDBWrapper dbw(ph, (1 << 20));
fs::path lockPath = ph / "LOCK"; fs::path lockPath = ph / "LOCK";
+2 -2
View File
@@ -208,7 +208,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
BOOST_AUTO_TEST_CASE(peer_discouragement) BOOST_AUTO_TEST_CASE(peer_discouragement)
{ {
const CChainParams& chainparams = Params(); const CChainParams& chainparams = Params();
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME); auto banman = std::make_unique<BanMan>(m_args.GetDataDirPath() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
auto connman = std::make_unique<CConnmanTest>(0x1337, 0x1337, *m_node.addrman); auto connman = std::make_unique<CConnmanTest>(0x1337, 0x1337, *m_node.addrman);
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(), auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
*m_node.scheduler, *m_node.chainman, *m_node.mempool, false); *m_node.scheduler, *m_node.chainman, *m_node.mempool, false);
@@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
BOOST_AUTO_TEST_CASE(DoS_bantime) BOOST_AUTO_TEST_CASE(DoS_bantime)
{ {
const CChainParams& chainparams = Params(); const CChainParams& chainparams = Params();
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME); auto banman = std::make_unique<BanMan>(m_args.GetDataDirPath() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman); auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(), auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
*m_node.scheduler, *m_node.chainman, *m_node.mempool, false); *m_node.scheduler, *m_node.chainman, *m_node.mempool, false);
+4 -4
View File
@@ -14,7 +14,7 @@ BOOST_FIXTURE_TEST_SUITE(flatfile_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(flatfile_filename) BOOST_AUTO_TEST_CASE(flatfile_filename)
{ {
const auto data_dir = GetDataDir(); const auto data_dir = m_args.GetDataDirPath();
FlatFilePos pos(456, 789); FlatFilePos pos(456, 789);
@@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(flatfile_filename)
BOOST_AUTO_TEST_CASE(flatfile_open) BOOST_AUTO_TEST_CASE(flatfile_open)
{ {
const auto data_dir = GetDataDir(); const auto data_dir = m_args.GetDataDirPath();
FlatFileSeq seq(data_dir, "a", 16 * 1024); FlatFileSeq seq(data_dir, "a", 16 * 1024);
std::string line1("A purely peer-to-peer version of electronic cash would allow online " std::string line1("A purely peer-to-peer version of electronic cash would allow online "
@@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(flatfile_open)
BOOST_AUTO_TEST_CASE(flatfile_allocate) BOOST_AUTO_TEST_CASE(flatfile_allocate)
{ {
const auto data_dir = GetDataDir(); const auto data_dir = m_args.GetDataDirPath();
FlatFileSeq seq(data_dir, "a", 100); FlatFileSeq seq(data_dir, "a", 100);
bool out_of_space; bool out_of_space;
@@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(flatfile_allocate)
BOOST_AUTO_TEST_CASE(flatfile_flush) BOOST_AUTO_TEST_CASE(flatfile_flush)
{ {
const auto data_dir = GetDataDir(); const auto data_dir = m_args.GetDataDirPath();
FlatFileSeq seq(data_dir, "a", 100); FlatFileSeq seq(data_dir, "a", 100);
bool out_of_space; bool out_of_space;
+1 -1
View File
@@ -13,7 +13,7 @@ BOOST_FIXTURE_TEST_SUITE(fs_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(fsbridge_fstream) BOOST_AUTO_TEST_CASE(fsbridge_fstream)
{ {
fs::path tmpfolder = GetDataDir(); fs::path tmpfolder = m_args.GetDataDirPath();
// tmpfile1 should be the same as tmpfile2 // tmpfile1 should be the same as tmpfile2
fs::path tmpfile1 = tmpfolder / "fs_tests_₿_🏃"; fs::path tmpfile1 = tmpfolder / "fs_tests_₿_🏃";
fs::path tmpfile2 = tmpfolder / "fs_tests_₿_🏃"; fs::path tmpfile2 = tmpfolder / "fs_tests_₿_🏃";
+60 -60
View File
@@ -18,7 +18,7 @@ namespace getarg_tests{
protected: protected:
void SetupArgs(const std::vector<std::pair<std::string, unsigned int>>& args); void SetupArgs(const std::vector<std::pair<std::string, unsigned int>>& args);
void ResetArgs(const std::string& strArg); void ResetArgs(const std::string& strArg);
ArgsManager m_args; ArgsManager m_local_args;
}; };
} }
@@ -39,14 +39,14 @@ void LocalTestingSetup :: ResetArgs(const std::string& strArg)
vecChar.push_back(s.c_str()); vecChar.push_back(s.c_str());
std::string error; std::string error;
BOOST_CHECK(m_args.ParseParameters(vecChar.size(), vecChar.data(), error)); BOOST_CHECK(m_local_args.ParseParameters(vecChar.size(), vecChar.data(), error));
} }
void LocalTestingSetup :: SetupArgs(const std::vector<std::pair<std::string, unsigned int>>& args) void LocalTestingSetup :: SetupArgs(const std::vector<std::pair<std::string, unsigned int>>& args)
{ {
m_args.ClearArgs(); m_local_args.ClearArgs();
for (const auto& arg : args) { for (const auto& arg : args) {
m_args.AddArg(arg.first, "", arg.second, OptionsCategory::OPTIONS); m_local_args.AddArg(arg.first, "", arg.second, OptionsCategory::OPTIONS);
} }
} }
@@ -55,52 +55,52 @@ BOOST_AUTO_TEST_CASE(boolarg)
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY); const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
SetupArgs({foo}); SetupArgs({foo});
ResetArgs("-foo"); ResetArgs("-foo");
BOOST_CHECK(m_args.GetBoolArg("-foo", false)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(m_args.GetBoolArg("-foo", true)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", true));
BOOST_CHECK(!m_args.GetBoolArg("-fo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-fo", false));
BOOST_CHECK(m_args.GetBoolArg("-fo", true)); BOOST_CHECK(m_local_args.GetBoolArg("-fo", true));
BOOST_CHECK(!m_args.GetBoolArg("-fooo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-fooo", false));
BOOST_CHECK(m_args.GetBoolArg("-fooo", true)); BOOST_CHECK(m_local_args.GetBoolArg("-fooo", true));
ResetArgs("-foo=0"); ResetArgs("-foo=0");
BOOST_CHECK(!m_args.GetBoolArg("-foo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(!m_args.GetBoolArg("-foo", true)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", true));
ResetArgs("-foo=1"); ResetArgs("-foo=1");
BOOST_CHECK(m_args.GetBoolArg("-foo", false)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(m_args.GetBoolArg("-foo", true)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", true));
// New 0.6 feature: auto-map -nosomething to !-something: // New 0.6 feature: auto-map -nosomething to !-something:
ResetArgs("-nofoo"); ResetArgs("-nofoo");
BOOST_CHECK(!m_args.GetBoolArg("-foo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(!m_args.GetBoolArg("-foo", true)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", true));
ResetArgs("-nofoo=1"); ResetArgs("-nofoo=1");
BOOST_CHECK(!m_args.GetBoolArg("-foo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(!m_args.GetBoolArg("-foo", true)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", true));
ResetArgs("-foo -nofoo"); // -nofoo should win ResetArgs("-foo -nofoo"); // -nofoo should win
BOOST_CHECK(!m_args.GetBoolArg("-foo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(!m_args.GetBoolArg("-foo", true)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", true));
ResetArgs("-foo=1 -nofoo=1"); // -nofoo should win ResetArgs("-foo=1 -nofoo=1"); // -nofoo should win
BOOST_CHECK(!m_args.GetBoolArg("-foo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(!m_args.GetBoolArg("-foo", true)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", true));
ResetArgs("-foo=0 -nofoo=0"); // -nofoo=0 should win ResetArgs("-foo=0 -nofoo=0"); // -nofoo=0 should win
BOOST_CHECK(m_args.GetBoolArg("-foo", false)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(m_args.GetBoolArg("-foo", true)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", true));
// New 0.6 feature: treat -- same as -: // New 0.6 feature: treat -- same as -:
ResetArgs("--foo=1"); ResetArgs("--foo=1");
BOOST_CHECK(m_args.GetBoolArg("-foo", false)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(m_args.GetBoolArg("-foo", true)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", true));
ResetArgs("--nofoo=1"); ResetArgs("--nofoo=1");
BOOST_CHECK(!m_args.GetBoolArg("-foo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", false));
BOOST_CHECK(!m_args.GetBoolArg("-foo", true)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", true));
} }
@@ -110,24 +110,24 @@ BOOST_AUTO_TEST_CASE(stringarg)
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY); const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
SetupArgs({foo, bar}); SetupArgs({foo, bar});
ResetArgs(""); ResetArgs("");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", ""), ""); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", ""), "");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", "eleven"), "eleven"); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", "eleven"), "eleven");
ResetArgs("-foo -bar"); ResetArgs("-foo -bar");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", ""), ""); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", ""), "");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", "eleven"), ""); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", "eleven"), "");
ResetArgs("-foo="); ResetArgs("-foo=");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", ""), ""); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", ""), "");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", "eleven"), ""); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", "eleven"), "");
ResetArgs("-foo=11"); ResetArgs("-foo=11");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", ""), "11"); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", ""), "11");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", "eleven"), "11"); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", "eleven"), "11");
ResetArgs("-foo=eleven"); ResetArgs("-foo=eleven");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", ""), "eleven"); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", ""), "eleven");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", "eleven"), "eleven"); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", "eleven"), "eleven");
} }
@@ -137,20 +137,20 @@ BOOST_AUTO_TEST_CASE(intarg)
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY); const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
SetupArgs({foo, bar}); SetupArgs({foo, bar});
ResetArgs(""); ResetArgs("");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", 11), 11); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", 11), 11);
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", 0), 0); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", 0), 0);
ResetArgs("-foo -bar"); ResetArgs("-foo -bar");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", 11), 0); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", 11), 0);
BOOST_CHECK_EQUAL(m_args.GetArg("-bar", 11), 0); BOOST_CHECK_EQUAL(m_local_args.GetArg("-bar", 11), 0);
ResetArgs("-foo=11 -bar=12"); ResetArgs("-foo=11 -bar=12");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", 0), 11); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", 0), 11);
BOOST_CHECK_EQUAL(m_args.GetArg("-bar", 11), 12); BOOST_CHECK_EQUAL(m_local_args.GetArg("-bar", 11), 12);
ResetArgs("-foo=NaN -bar=NotANumber"); ResetArgs("-foo=NaN -bar=NotANumber");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", 1), 0); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", 1), 0);
BOOST_CHECK_EQUAL(m_args.GetArg("-bar", 11), 0); BOOST_CHECK_EQUAL(m_local_args.GetArg("-bar", 11), 0);
} }
BOOST_AUTO_TEST_CASE(doubledash) BOOST_AUTO_TEST_CASE(doubledash)
@@ -159,11 +159,11 @@ BOOST_AUTO_TEST_CASE(doubledash)
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY); const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
SetupArgs({foo, bar}); SetupArgs({foo, bar});
ResetArgs("--foo"); ResetArgs("--foo");
BOOST_CHECK_EQUAL(m_args.GetBoolArg("-foo", false), true); BOOST_CHECK_EQUAL(m_local_args.GetBoolArg("-foo", false), true);
ResetArgs("--foo=verbose --bar=1"); ResetArgs("--foo=verbose --bar=1");
BOOST_CHECK_EQUAL(m_args.GetArg("-foo", ""), "verbose"); BOOST_CHECK_EQUAL(m_local_args.GetArg("-foo", ""), "verbose");
BOOST_CHECK_EQUAL(m_args.GetArg("-bar", 0), 1); BOOST_CHECK_EQUAL(m_local_args.GetArg("-bar", 0), 1);
} }
BOOST_AUTO_TEST_CASE(boolargno) BOOST_AUTO_TEST_CASE(boolargno)
@@ -172,24 +172,24 @@ BOOST_AUTO_TEST_CASE(boolargno)
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY); const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
SetupArgs({foo, bar}); SetupArgs({foo, bar});
ResetArgs("-nofoo"); ResetArgs("-nofoo");
BOOST_CHECK(!m_args.GetBoolArg("-foo", true)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", true));
BOOST_CHECK(!m_args.GetBoolArg("-foo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", false));
ResetArgs("-nofoo=1"); ResetArgs("-nofoo=1");
BOOST_CHECK(!m_args.GetBoolArg("-foo", true)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", true));
BOOST_CHECK(!m_args.GetBoolArg("-foo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", false));
ResetArgs("-nofoo=0"); ResetArgs("-nofoo=0");
BOOST_CHECK(m_args.GetBoolArg("-foo", true)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", true));
BOOST_CHECK(m_args.GetBoolArg("-foo", false)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", false));
ResetArgs("-foo --nofoo"); // --nofoo should win ResetArgs("-foo --nofoo"); // --nofoo should win
BOOST_CHECK(!m_args.GetBoolArg("-foo", true)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", true));
BOOST_CHECK(!m_args.GetBoolArg("-foo", false)); BOOST_CHECK(!m_local_args.GetBoolArg("-foo", false));
ResetArgs("-nofoo -foo"); // foo always wins: ResetArgs("-nofoo -foo"); // foo always wins:
BOOST_CHECK(m_args.GetBoolArg("-foo", true)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", true));
BOOST_CHECK(m_args.GetBoolArg("-foo", false)); BOOST_CHECK(m_local_args.GetBoolArg("-foo", false));
} }
BOOST_AUTO_TEST_CASE(logargs) BOOST_AUTO_TEST_CASE(logargs)
@@ -209,7 +209,7 @@ BOOST_AUTO_TEST_CASE(logargs)
}); });
// Log the arguments // Log the arguments
m_args.LogArgs(); m_local_args.LogArgs();
LogInstance().DeleteCallback(print_connection); LogInstance().DeleteCallback(print_connection);
// Check that what should appear does, and what shouldn't doesn't. // Check that what should appear does, and what shouldn't doesn't.
+1 -1
View File
@@ -45,7 +45,7 @@ BOOST_FIXTURE_TEST_SUITE(settings_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(ReadWrite) BOOST_AUTO_TEST_CASE(ReadWrite)
{ {
fs::path path = GetDataDir() / "settings.json"; fs::path path = m_args.GetDataDirPath() / "settings.json";
WriteText(path, R"({ WriteText(path, R"({
"string": "string", "string": "string",
+5 -3
View File
@@ -71,7 +71,8 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
} }
BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args) BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
: m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()} : m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()},
m_args{}
{ {
const std::vector<const char*> arguments = Cat( const std::vector<const char*> arguments = Cat(
{ {
@@ -87,8 +88,9 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
extra_args); extra_args);
util::ThreadRename("test"); util::ThreadRename("test");
fs::create_directories(m_path_root); fs::create_directories(m_path_root);
m_args.ForceSetArg("-datadir", m_path_root.string());
gArgs.ForceSetArg("-datadir", m_path_root.string()); gArgs.ForceSetArg("-datadir", m_path_root.string());
ClearDatadirCache(); gArgs.ClearPathCache();
{ {
SetupServerArgs(m_node); SetupServerArgs(m_node);
std::string error; std::string error;
@@ -191,7 +193,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
} }
m_node.addrman = std::make_unique<CAddrMan>(); m_node.addrman = std::make_unique<CAddrMan>();
m_node.banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME); m_node.banman = std::make_unique<BanMan>(m_args.GetDataDirPath() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
m_node.connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman); // Deterministic randomness for tests. m_node.connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman); // Deterministic randomness for tests.
m_node.peerman = PeerManager::make(chainparams, *m_node.connman, *m_node.addrman, m_node.peerman = PeerManager::make(chainparams, *m_node.connman, *m_node.addrman,
m_node.banman.get(), *m_node.scheduler, *m_node.chainman, m_node.banman.get(), *m_node.scheduler, *m_node.chainman,
+2
View File
@@ -8,6 +8,7 @@
#include <chainparamsbase.h> #include <chainparamsbase.h>
#include <fs.h> #include <fs.h>
#include <key.h> #include <key.h>
#include <util/system.h>
#include <node/context.h> #include <node/context.h>
#include <pubkey.h> #include <pubkey.h>
#include <random.h> #include <random.h>
@@ -80,6 +81,7 @@ struct BasicTestingSetup {
~BasicTestingSetup(); ~BasicTestingSetup();
const fs::path m_path_root; const fs::path m_path_root;
ArgsManager m_args;
}; };
/** Testing setup that performs all steps up until right before /** Testing setup that performs all steps up until right before
+24 -19
View File
@@ -49,24 +49,27 @@ BOOST_FIXTURE_TEST_SUITE(util_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(util_datadir) BOOST_AUTO_TEST_CASE(util_datadir)
{ {
ClearDatadirCache(); // Use local args variable instead of m_args to avoid making assumptions about test setup
const fs::path dd_norm = GetDataDir(); ArgsManager args;
args.ForceSetArg("-datadir", m_path_root.string());
gArgs.ForceSetArg("-datadir", dd_norm.string() + "/"); const fs::path dd_norm = args.GetDataDirPath();
ClearDatadirCache();
BOOST_CHECK_EQUAL(dd_norm, GetDataDir());
gArgs.ForceSetArg("-datadir", dd_norm.string() + "/."); args.ForceSetArg("-datadir", dd_norm.string() + "/");
ClearDatadirCache(); args.ClearPathCache();
BOOST_CHECK_EQUAL(dd_norm, GetDataDir()); BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirPath());
gArgs.ForceSetArg("-datadir", dd_norm.string() + "/./"); args.ForceSetArg("-datadir", dd_norm.string() + "/.");
ClearDatadirCache(); args.ClearPathCache();
BOOST_CHECK_EQUAL(dd_norm, GetDataDir()); BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirPath());
gArgs.ForceSetArg("-datadir", dd_norm.string() + "/.//"); args.ForceSetArg("-datadir", dd_norm.string() + "/./");
ClearDatadirCache(); args.ClearPathCache();
BOOST_CHECK_EQUAL(dd_norm, GetDataDir()); BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirPath());
args.ForceSetArg("-datadir", dd_norm.string() + "/.//");
args.ClearPathCache();
BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirPath());
} }
BOOST_AUTO_TEST_CASE(util_check) BOOST_AUTO_TEST_CASE(util_check)
@@ -1143,21 +1146,23 @@ BOOST_AUTO_TEST_CASE(util_ReadWriteSettings)
{ {
// Test writing setting. // Test writing setting.
TestArgsManager args1; TestArgsManager args1;
args1.ForceSetArg("-datadir", m_path_root.string());
args1.LockSettings([&](util::Settings& settings) { settings.rw_settings["name"] = "value"; }); args1.LockSettings([&](util::Settings& settings) { settings.rw_settings["name"] = "value"; });
args1.WriteSettingsFile(); args1.WriteSettingsFile();
// Test reading setting. // Test reading setting.
TestArgsManager args2; TestArgsManager args2;
args2.ForceSetArg("-datadir", m_path_root.string());
args2.ReadSettingsFile(); args2.ReadSettingsFile();
args2.LockSettings([&](util::Settings& settings) { BOOST_CHECK_EQUAL(settings.rw_settings["name"].get_str(), "value"); }); args2.LockSettings([&](util::Settings& settings) { BOOST_CHECK_EQUAL(settings.rw_settings["name"].get_str(), "value"); });
// Test error logging, and remove previously written setting. // Test error logging, and remove previously written setting.
{ {
ASSERT_DEBUG_LOG("Failed renaming settings file"); ASSERT_DEBUG_LOG("Failed renaming settings file");
fs::remove(GetDataDir() / "settings.json"); fs::remove(args1.GetDataDirPath() / "settings.json");
fs::create_directory(GetDataDir() / "settings.json"); fs::create_directory(args1.GetDataDirPath() / "settings.json");
args2.WriteSettingsFile(); args2.WriteSettingsFile();
fs::remove(GetDataDir() / "settings.json"); fs::remove(args1.GetDataDirPath() / "settings.json");
} }
} }
@@ -1796,7 +1801,7 @@ static constexpr char ExitCommand = 'X';
BOOST_AUTO_TEST_CASE(test_LockDirectory) BOOST_AUTO_TEST_CASE(test_LockDirectory)
{ {
fs::path dirname = GetDataDir() / "lock_dir"; fs::path dirname = m_args.GetDataDirPath() / "lock_dir";
const std::string lockname = ".lock"; const std::string lockname = ".lock";
#ifndef WIN32 #ifndef WIN32
// Revert SIGCHLD to default, otherwise boost.test will catch and fail on // Revert SIGCHLD to default, otherwise boost.test will catch and fail on
@@ -1885,7 +1890,7 @@ BOOST_AUTO_TEST_CASE(test_LockDirectory)
BOOST_AUTO_TEST_CASE(test_DirIsWritable) BOOST_AUTO_TEST_CASE(test_DirIsWritable)
{ {
// Should be able to write to the data dir. // Should be able to write to the data dir.
fs::path tmpdirname = GetDataDir(); fs::path tmpdirname = m_args.GetDataDirPath();
BOOST_CHECK_EQUAL(DirIsWritable(tmpdirname), true); BOOST_CHECK_EQUAL(DirIsWritable(tmpdirname), true);
// Should not be able to write to a non-existent dir. // Should not be able to write to a non-existent dir.
+82 -82
View File
@@ -235,6 +235,19 @@ static bool CheckValid(const std::string& key, const util::SettingsValue& val, u
return true; return true;
} }
namespace {
fs::path StripRedundantLastElementsOfPath(const fs::path& path)
{
auto result = path;
while (result.filename().string() == ".") {
result = result.parent_path();
}
assert(fs::equivalent(result, path));
return result;
}
} // namespace
// Define default constructor and destructor that are not inline, so code instantiating this class doesn't need to // Define default constructor and destructor that are not inline, so code instantiating this class doesn't need to
// #include class definitions for all members. // #include class definitions for all members.
// For example, m_settings has an internal dependency on univalue. // For example, m_settings has an internal dependency on univalue.
@@ -375,6 +388,72 @@ std::optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) co
return std::nullopt; 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);
fs::path& path = net_specific ? m_cached_network_datadir_path : m_cached_datadir_path;
// Cache the path to avoid calling fs::create_directories on every call of
// this function
if (!path.empty()) return path;
std::string datadir = GetArg("-datadir", "");
if (!datadir.empty()) {
path = fs::system_complete(datadir);
if (!fs::is_directory(path)) {
path = "";
return path;
}
} else {
path = GetDefaultDataDir();
}
if (net_specific)
path /= BaseParams().DataDir();
if (fs::create_directories(path)) {
// This is the first run, create wallets subdirectory too
fs::create_directories(path / "wallets");
}
path = StripRedundantLastElementsOfPath(path);
return path;
}
void ArgsManager::ClearPathCache()
{
LOCK(cs_args);
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 std::optional<const ArgsManager::Command> ArgsManager::GetCommand() const
{ {
Command ret; Command ret;
@@ -434,7 +513,7 @@ bool ArgsManager::GetSettingsPath(fs::path* filepath, bool temp) const
} }
if (filepath) { if (filepath) {
std::string settings = GetArg("-settings", BITCOIN_SETTINGS_FILENAME); std::string settings = GetArg("-settings", BITCOIN_SETTINGS_FILENAME);
*filepath = fsbridge::AbsPathJoin(GetDataDir(/* net_specific= */ true), temp ? settings + ".tmp" : settings); *filepath = fsbridge::AbsPathJoin(GetDataDirPath(/* net_specific= */ true), temp ? settings + ".tmp" : settings);
} }
return true; return true;
} }
@@ -723,79 +802,9 @@ fs::path GetDefaultDataDir()
#endif #endif
} }
namespace {
fs::path StripRedundantLastElementsOfPath(const fs::path& path)
{
auto result = path;
while (result.filename().string() == ".") {
result = result.parent_path();
}
assert(fs::equivalent(result, path));
return result;
}
} // namespace
static fs::path g_blocks_path_cache_net_specific;
static fs::path pathCached;
static fs::path pathCachedNetSpecific;
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) const fs::path &GetDataDir(bool fNetSpecific)
{ {
LOCK(csPathCached); return gArgs.GetDataDirPath(fNetSpecific);
fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
// Cache the path to avoid calling fs::create_directories on every call of
// this function
if (!path.empty()) return path;
std::string datadir = gArgs.GetArg("-datadir", "");
if (!datadir.empty()) {
path = fs::system_complete(datadir);
if (!fs::is_directory(path)) {
path = "";
return path;
}
} else {
path = GetDefaultDataDir();
}
if (fNetSpecific)
path /= BaseParams().DataDir();
if (fs::create_directories(path)) {
// This is the first run, create wallets subdirectory too
fs::create_directories(path / "wallets");
}
path = StripRedundantLastElementsOfPath(path);
return path;
} }
bool CheckDataDirOption() bool CheckDataDirOption()
@@ -804,15 +813,6 @@ bool CheckDataDirOption()
return datadir.empty() || fs::is_directory(fs::system_complete(datadir)); return datadir.empty() || fs::is_directory(fs::system_complete(datadir));
} }
void ClearDatadirCache()
{
LOCK(csPathCached);
pathCached = fs::path();
pathCachedNetSpecific = fs::path();
g_blocks_path_cache_net_specific = fs::path();
}
fs::path GetConfigFile(const std::string& confPath) fs::path GetConfigFile(const std::string& confPath)
{ {
return AbsPathForConfigVal(fs::path(confPath), false); return AbsPathForConfigVal(fs::path(confPath), false);
@@ -971,7 +971,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
} }
// If datadir is changed in .conf file: // If datadir is changed in .conf file:
ClearDatadirCache(); gArgs.ClearPathCache();
if (!CheckDataDirOption()) { if (!CheckDataDirOption()) {
error = strprintf("specified data directory \"%s\" does not exist.", GetArg("-datadir", "")); error = strprintf("specified data directory \"%s\" does not exist.", GetArg("-datadir", ""));
return false; return false;
+24 -4
View File
@@ -91,13 +91,9 @@ void ReleaseDirectoryLocks();
bool TryCreateDirectories(const fs::path& p); bool TryCreateDirectories(const fs::path& p);
fs::path GetDefaultDataDir(); fs::path GetDefaultDataDir();
// The blocks directory is always net specific.
const fs::path &GetBlocksDir();
const fs::path &GetDataDir(bool fNetSpecific = true); const fs::path &GetDataDir(bool fNetSpecific = true);
// Return true if -datadir option points to a valid directory or is not specified. // Return true if -datadir option points to a valid directory or is not specified.
bool CheckDataDirOption(); bool CheckDataDirOption();
/** Tests only */
void ClearDatadirCache();
fs::path GetConfigFile(const std::string& confPath); fs::path GetConfigFile(const std::string& confPath);
#ifdef WIN32 #ifdef WIN32
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true); fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
@@ -200,6 +196,9 @@ protected:
std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args GUARDED_BY(cs_args); 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}; bool m_accept_any_command GUARDED_BY(cs_args){true};
std::list<SectionInfo> m_config_sections GUARDED_BY(cs_args); 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);
[[nodiscard]] bool ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys = false); [[nodiscard]] bool ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys = false);
@@ -263,6 +262,27 @@ public:
*/ */
std::optional<const Command> GetCommand() const; 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
* @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;
/**
* Clear cached directory paths
*/
void ClearPathCache();
/** /**
* Return a vector of strings of the given argument * Return a vector of strings of the given argument
* *
+3 -3
View File
@@ -2204,7 +2204,7 @@ bool CChainState::FlushStateToDisk(
// Write blocks and block index to disk. // Write blocks and block index to disk.
if (fDoFullFlush || fPeriodicWrite) { if (fDoFullFlush || fPeriodicWrite) {
// Depend on nMinDiskSpace to ensure we can write block index // Depend on nMinDiskSpace to ensure we can write block index
if (!CheckDiskSpace(GetBlocksDir())) { if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) {
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!")); return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
} }
{ {
@@ -3890,12 +3890,12 @@ void BlockManager::FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPr
static FlatFileSeq BlockFileSeq() static FlatFileSeq BlockFileSeq()
{ {
return FlatFileSeq(GetBlocksDir(), "blk", gArgs.GetBoolArg("-fastprune", false) ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE); return FlatFileSeq(gArgs.GetBlocksDirPath(), "blk", gArgs.GetBoolArg("-fastprune", false) ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE);
} }
static FlatFileSeq UndoFileSeq() static FlatFileSeq UndoFileSeq()
{ {
return FlatFileSeq(GetBlocksDir(), "rev", UNDOFILE_CHUNK_SIZE); return FlatFileSeq(gArgs.GetBlocksDirPath(), "rev", UNDOFILE_CHUNK_SIZE);
} }
FILE* OpenBlockFile(const FlatFilePos &pos, bool fReadOnly) { FILE* OpenBlockFile(const FlatFilePos &pos, bool fReadOnly) {