fixing broken tests on Windows, merge GetDataDir fixes

This commit is contained in:
Brannon King 2020-02-10 08:49:34 -07:00 committed by Anthony Fieroni
parent 4a6b3b7bf2
commit 91760d0252
5 changed files with 28 additions and 13 deletions

View file

@ -1649,7 +1649,7 @@ bool AppInitMain(InitInterfaces& interfaces)
if (fReindex) {
// remove old LevelDB indexes
boost::system::error_code ec;
fs::remove_all(GetDataDir() / "blocks" / "index", ec);
fs::remove_all(GetBlocksDir() / "index", ec);
fs::remove_all(GetDataDir() / "chainstate", ec);
fs::remove_all(GetDataDir() / "claimtrie", ec);
}

View file

@ -549,6 +549,12 @@ void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strV
m_override_args[strArg] = {strValue};
}
void ArgsManager::ForceClearArg(const std::string& strArg)
{
LOCK(cs_args);
m_override_args.erase(strArg);
}
void ArgsManager::AddArg(const std::string& name, const std::string& help, unsigned int flags, const OptionsCategory& cat)
{
// Split arg name from its help param
@ -735,16 +741,21 @@ const fs::path &GetBlocksDir()
if (gArgs.IsArgSet("-blocksdir")) {
path = fs::system_complete(gArgs.GetArg("-blocksdir", ""));
if (!fs::is_directory(path)) {
path = "";
return path;
if (fs::exists(path) && !fs::is_directory(path)) {
LogPrintf("%s: %s is not a directory, falling back to GetDataDir\n", __func__, path);
path.clear();
}
} else {
path = GetDataDir(false);
}
bool usingDataDir = path.empty();
if (usingDataDir)
path = GetDataDir(false);
path /= BaseParams().DataDir();
path /= "blocks";
if (usingDataDir)
path /= "blocks";
fs::create_directories(path);
return path;
}
@ -761,13 +772,15 @@ const fs::path &GetDataDir(bool fNetSpecific)
std::string datadir = gArgs.GetArg("-datadir", "");
if (!datadir.empty()) {
path = fs::system_complete(datadir);
if (!fs::is_directory(path)) {
path = "";
return path;
if (fs::exists(path) && !fs::is_directory(path)) {
LogPrintf("%s: %s is not a directory, falling back to GetDefaultDataDir\n", __func__, path);
path.clear();
}
} else {
path = GetDefaultDataDir();
}
if (path.empty())
path = GetDefaultDataDir();
if (fNetSpecific)
path /= BaseParams().DataDir();

View file

@ -263,6 +263,7 @@ public:
// Forces an arg setting. Called by SoftSetArg() if the arg hasn't already
// been set. Also called directly in testing.
void ForceSetArg(const std::string& strArg, const std::string& strValue);
void ForceClearArg(const std::string& strArg);
/**
* Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.

View file

@ -4771,7 +4771,7 @@ bool LoadBlockIndex(const CChainParams& chainparams)
needs_init = g_blockman.m_block_index.empty();
if (needs_init) {
auto blockDir = GetDataDir() / "blocks";
auto& blockDir = GetBlocksDir();
for (auto it: fs::directory_iterator(blockDir)) {
boost::system::error_code ec;
if (fs::file_size(it, ec) > 100000000) {

View file

@ -36,6 +36,7 @@ InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainNam
InitWalletDirTestingSetup::~InitWalletDirTestingSetup()
{
gArgs.ForceClearArg("-walletdir");
fs::current_path(m_cwd);
}