Skip to content

Commit a839303

Browse files
committed
Merge #21244: Move GetDataDir to ArgsManager
bb8d1c6 Change ClearDataDirPathCache() to ArgsManager.ClearPathCache(). (Kiminuo) b4190ef Change GetBlocksDir() to ArgsManager.GetBlocksDirPath(). (Kiminuo) 83292e2 scripted-diff: Modify unit tests to use the ArgsManager in the BasicTestingSetup class instead of implicitly relying on gArgs. (Kiminuo) 55c68e6 scripted-diff: Replace m_args with m_local_args in getarg_tests.cpp (Kiminuo) 511ce3a BasicTestingSetup: Add ArgsManager. (Kiminuo) 1cb52ba Modify "util_datadir" unit test to not use gArgs. (Kiminuo) 1add318 Move GetDataDir(fNetSpecific) implementation to ArgsManager. (Kiminuo) 70cdf67 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 bb8d1c6. Just minor const/naming changes and splitting/scripting commits since last review MarcoFalke: review ACK bb8d1c6 📓 hebasto: re-ACK bb8d1c6, addressed comments, and two commits made scripted-diffs since my [previous](bitcoin/bitcoin#21244 (review)) review. Tree-SHA512: ba9408c22129d6572beaa103dca0324131766f06d562bb7d6b9e214a0a4d40b0216ce861384562bde24b744003b3fbe6fac239061c8fd798abd3981ebc1b9019
2 parents 67a3593 + bb8d1c6 commit a839303

14 files changed

+222
-193
lines changed

src/init.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static void CleanupBlockRevFiles()
637637
// Remove the rev files immediately and insert the blk file paths into an
638638
// ordered map keyed by block file index.
639639
LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n");
640-
fs::path blocksdir = GetBlocksDir();
640+
fs::path blocksdir = gArgs.GetBlocksDirPath();
641641
for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) {
642642
if (fs::is_regular_file(*it) &&
643643
it->path().filename().string().length() == 12 &&
@@ -919,7 +919,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
919919
InitWarning(warnings);
920920
}
921921

922-
if (!fs::is_directory(GetBlocksDir())) {
922+
if (!fs::is_directory(gArgs.GetBlocksDirPath())) {
923923
return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), args.GetArg("-blocksdir", "")));
924924
}
925925

@@ -1759,8 +1759,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17591759
InitError(strprintf(_("Error: Disk space is low for %s"), GetDataDir()));
17601760
return false;
17611761
}
1762-
if (!CheckDiskSpace(GetBlocksDir())) {
1763-
InitError(strprintf(_("Error: Disk space is low for %s"), GetBlocksDir()));
1762+
if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) {
1763+
InitError(strprintf(_("Error: Disk space is low for %s"), gArgs.GetBlocksDirPath()));
17641764
return false;
17651765
}
17661766

src/qt/clientmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ QString ClientModel::dataDir() const
216216

217217
QString ClientModel::blocksDir() const
218218
{
219-
return GUIUtil::boostPathToQString(GetBlocksDir());
219+
return GUIUtil::boostPathToQString(gArgs.GetBlocksDirPath());
220220
}
221221

222222
void ClientModel::updateBanlist()

src/test/dbwrapper_tests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper)
2626
{
2727
// Perform tests both obfuscated and non-obfuscated.
2828
for (const bool obfuscate : {false, true}) {
29-
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_obfuscate_true" : "dbwrapper_obfuscate_false");
29+
fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_obfuscate_true" : "dbwrapper_obfuscate_false");
3030
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
3131
char key = 'k';
3232
uint256 in = InsecureRand256();
@@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_basic_data)
4545
{
4646
// Perform tests both obfuscated and non-obfuscated.
4747
for (bool obfuscate : {false, true}) {
48-
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_1_obfuscate_true" : "dbwrapper_1_obfuscate_false");
48+
fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_1_obfuscate_true" : "dbwrapper_1_obfuscate_false");
4949
CDBWrapper dbw(ph, (1 << 20), false, true, obfuscate);
5050

5151
uint256 res;
@@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_batch)
126126
{
127127
// Perform tests both obfuscated and non-obfuscated.
128128
for (const bool obfuscate : {false, true}) {
129-
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_batch_obfuscate_true" : "dbwrapper_batch_obfuscate_false");
129+
fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_batch_obfuscate_true" : "dbwrapper_batch_obfuscate_false");
130130
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
131131

132132
char key = 'i';
@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
162162
{
163163
// Perform tests both obfuscated and non-obfuscated.
164164
for (const bool obfuscate : {false, true}) {
165-
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_iterator_obfuscate_true" : "dbwrapper_iterator_obfuscate_false");
165+
fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_iterator_obfuscate_true" : "dbwrapper_iterator_obfuscate_false");
166166
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
167167

168168
// The two keys are intentionally chosen for ordering
@@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
202202
BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
203203
{
204204
// We're going to share this fs::path between two wrappers
205-
fs::path ph = GetDataDir() / "existing_data_no_obfuscate";
205+
fs::path ph = m_args.GetDataDirPath() / "existing_data_no_obfuscate";
206206
create_directories(ph);
207207

208208
// Set up a non-obfuscated wrapper to write some initial data.
@@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
243243
BOOST_AUTO_TEST_CASE(existing_data_reindex)
244244
{
245245
// We're going to share this fs::path between two wrappers
246-
fs::path ph = GetDataDir() / "existing_data_reindex";
246+
fs::path ph = m_args.GetDataDirPath() / "existing_data_reindex";
247247
create_directories(ph);
248248

249249
// Set up a non-obfuscated wrapper to write some initial data.
@@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
278278

279279
BOOST_AUTO_TEST_CASE(iterator_ordering)
280280
{
281-
fs::path ph = GetDataDir() / "iterator_ordering";
281+
fs::path ph = m_args.GetDataDirPath() / "iterator_ordering";
282282
CDBWrapper dbw(ph, (1 << 20), true, false, false);
283283
for (int x=0x00; x<256; ++x) {
284284
uint8_t key = x;
@@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
358358
{
359359
char buf[10];
360360

361-
fs::path ph = GetDataDir() / "iterator_string_ordering";
361+
fs::path ph = m_args.GetDataDirPath() / "iterator_string_ordering";
362362
CDBWrapper dbw(ph, (1 << 20), true, false, false);
363363
for (int x=0x00; x<10; ++x) {
364364
for (int y = 0; y < 10; y++) {
@@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(unicodepath)
404404
// On Windows this test will fail if the directory is created using
405405
// the ANSI CreateDirectoryA call and the code page isn't UTF8.
406406
// It will succeed if created with CreateDirectoryW.
407-
fs::path ph = GetDataDir() / "test_runner_₿_🏃_20191128_104644";
407+
fs::path ph = m_args.GetDataDirPath() / "test_runner_₿_🏃_20191128_104644";
408408
CDBWrapper dbw(ph, (1 << 20));
409409

410410
fs::path lockPath = ph / "LOCK";

src/test/denialofservice_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
208208
BOOST_AUTO_TEST_CASE(peer_discouragement)
209209
{
210210
const CChainParams& chainparams = Params();
211-
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
211+
auto banman = std::make_unique<BanMan>(m_args.GetDataDirPath() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
212212
auto connman = std::make_unique<CConnmanTest>(0x1337, 0x1337, *m_node.addrman);
213213
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
214214
*m_node.scheduler, *m_node.chainman, *m_node.mempool, false);
@@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
302302
BOOST_AUTO_TEST_CASE(DoS_bantime)
303303
{
304304
const CChainParams& chainparams = Params();
305-
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
305+
auto banman = std::make_unique<BanMan>(m_args.GetDataDirPath() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
306306
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
307307
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
308308
*m_node.scheduler, *m_node.chainman, *m_node.mempool, false);

src/test/flatfile_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ BOOST_FIXTURE_TEST_SUITE(flatfile_tests, BasicTestingSetup)
1414

1515
BOOST_AUTO_TEST_CASE(flatfile_filename)
1616
{
17-
const auto data_dir = GetDataDir();
17+
const auto data_dir = m_args.GetDataDirPath();
1818

1919
FlatFilePos pos(456, 789);
2020

@@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(flatfile_filename)
2727

2828
BOOST_AUTO_TEST_CASE(flatfile_open)
2929
{
30-
const auto data_dir = GetDataDir();
30+
const auto data_dir = m_args.GetDataDirPath();
3131
FlatFileSeq seq(data_dir, "a", 16 * 1024);
3232

3333
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)
8888

8989
BOOST_AUTO_TEST_CASE(flatfile_allocate)
9090
{
91-
const auto data_dir = GetDataDir();
91+
const auto data_dir = m_args.GetDataDirPath();
9292
FlatFileSeq seq(data_dir, "a", 100);
9393

9494
bool out_of_space;
@@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(flatfile_allocate)
108108

109109
BOOST_AUTO_TEST_CASE(flatfile_flush)
110110
{
111-
const auto data_dir = GetDataDir();
111+
const auto data_dir = m_args.GetDataDirPath();
112112
FlatFileSeq seq(data_dir, "a", 100);
113113

114114
bool out_of_space;

src/test/fs_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ BOOST_FIXTURE_TEST_SUITE(fs_tests, BasicTestingSetup)
1313

1414
BOOST_AUTO_TEST_CASE(fsbridge_fstream)
1515
{
16-
fs::path tmpfolder = GetDataDir();
16+
fs::path tmpfolder = m_args.GetDataDirPath();
1717
// tmpfile1 should be the same as tmpfile2
1818
fs::path tmpfile1 = tmpfolder / "fs_tests_₿_🏃";
1919
fs::path tmpfile2 = tmpfolder / "fs_tests_₿_🏃";

0 commit comments

Comments
 (0)