mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-08 21:59:10 +02:00
Merge #15864: Fix datadir handling
ffea41f530Enable all tests in feature_config_args.py (Hennadii Stepanov)66f5c17f8aUse CheckDataDirOption() for code uniformity (Hennadii Stepanov)7e33a18a34Fix datadir handling in bitcoin-cli (Hennadii Stepanov)b28dada374Fix datadir handling in bitcoin-qt (Hennadii Stepanov)50824093bbFix datadir handling in bitcoind (Hennadii Stepanov)740d41ce9fAdd CheckDataDirOption() function (Hennadii Stepanov)c1f325126cReturn absolute path early in AbsPathForConfigVal (Hennadii Stepanov) Pull request description: Fix #15240, see: https://github.com/bitcoin/bitcoin/issues/15240#issuecomment-487353760 Fix #15745 Fix broken `feature_config_args.py` tests (disabled by MarcoFalke@fabe28a0cdcfa13e0e595a0905e3642a960d3077). All test are enabled now. This PR is alternative to #13621. User's `$HOME` directory is not touched unnecessarily now. ~To make reviewing easier only `bitcoind` code is modified (neither `bitcoin-cli` nor `bitcoin-qt`).~ Refs: - https://github.com/bitcoin/bitcoin/issues/15745#issuecomment-479852569 by **laanwj** - #16220 Top commit has no ACKs. Tree-SHA512: 4a4cda10e0b67c8f374da0c9567003d2b566d948e7f8550fe246868b5794c15010e88ea206009480b9cd2f737f310a15e984f920730448f99a895893bed351df
This commit is contained in:
@@ -748,8 +748,9 @@ const fs::path &GetDataDir(bool fNetSpecific)
|
||||
// this function
|
||||
if (!path.empty()) return path;
|
||||
|
||||
if (gArgs.IsArgSet("-datadir")) {
|
||||
path = fs::system_complete(gArgs.GetArg("-datadir", ""));
|
||||
std::string datadir = gArgs.GetArg("-datadir", "");
|
||||
if (!datadir.empty()) {
|
||||
path = fs::system_complete(datadir);
|
||||
if (!fs::is_directory(path)) {
|
||||
path = "";
|
||||
return path;
|
||||
@@ -768,6 +769,12 @@ const fs::path &GetDataDir(bool fNetSpecific)
|
||||
return path;
|
||||
}
|
||||
|
||||
bool CheckDataDirOption()
|
||||
{
|
||||
std::string datadir = gArgs.GetArg("-datadir", "");
|
||||
return datadir.empty() || fs::is_directory(fs::system_complete(datadir));
|
||||
}
|
||||
|
||||
void ClearDatadirCache()
|
||||
{
|
||||
LOCK(csPathCached);
|
||||
@@ -937,7 +944,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
|
||||
|
||||
// If datadir is changed in .conf file:
|
||||
ClearDatadirCache();
|
||||
if (!fs::is_directory(GetDataDir(false))) {
|
||||
if (!CheckDataDirOption()) {
|
||||
error = strprintf("specified data directory \"%s\" does not exist.", gArgs.GetArg("-datadir", "").c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -1205,6 +1212,9 @@ int64_t GetStartupTime()
|
||||
|
||||
fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
|
||||
{
|
||||
if (path.is_absolute()) {
|
||||
return path;
|
||||
}
|
||||
return fs::absolute(path, GetDataDir(net_specific));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user