mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
merge bitcoin#20080: Strip any trailing / in -datadir and -blocksdir paths
This commit is contained in:
parent
18514d3469
commit
72396d59f8
@ -52,6 +52,28 @@ namespace BCLog {
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(util_tests, BasicTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_datadir)
|
||||
{
|
||||
ClearDatadirCache();
|
||||
const fs::path dd_norm = GetDataDir();
|
||||
|
||||
gArgs.ForceSetArg("-datadir", dd_norm.string() + "/");
|
||||
ClearDatadirCache();
|
||||
BOOST_CHECK_EQUAL(dd_norm, GetDataDir());
|
||||
|
||||
gArgs.ForceSetArg("-datadir", dd_norm.string() + "/.");
|
||||
ClearDatadirCache();
|
||||
BOOST_CHECK_EQUAL(dd_norm, GetDataDir());
|
||||
|
||||
gArgs.ForceSetArg("-datadir", dd_norm.string() + "/./");
|
||||
ClearDatadirCache();
|
||||
BOOST_CHECK_EQUAL(dd_norm, GetDataDir());
|
||||
|
||||
gArgs.ForceSetArg("-datadir", dd_norm.string() + "/.//");
|
||||
ClearDatadirCache();
|
||||
BOOST_CHECK_EQUAL(dd_norm, GetDataDir());
|
||||
}
|
||||
|
||||
namespace {
|
||||
class NoCopyOrMove
|
||||
{
|
||||
|
@ -35,6 +35,7 @@
|
||||
#endif // __linux__
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <fcntl.h>
|
||||
#include <sched.h>
|
||||
#include <sys/resource.h>
|
||||
@ -693,10 +694,9 @@ void PrintExceptionContinue(const std::exception_ptr pex, const char* pszExcepti
|
||||
|
||||
fs::path GetDefaultDataDir()
|
||||
{
|
||||
// Windows < Vista: C:\Documents and Settings\Username\Application Data\DashCore
|
||||
// Windows >= Vista: C:\Users\Username\AppData\Roaming\DashCore
|
||||
// Mac: ~/Library/Application Support/DashCore
|
||||
// Unix: ~/.dashcore
|
||||
// Windows: C:\Users\Username\AppData\Roaming\DashCore
|
||||
// macOS: ~/Library/Application Support/DashCore
|
||||
// Unix-like: ~/.dashcore
|
||||
#ifdef WIN32
|
||||
// Windows
|
||||
return GetSpecialFolderPath(CSIDL_APPDATA) / "DashCore";
|
||||
@ -708,15 +708,28 @@ fs::path GetDefaultDataDir()
|
||||
else
|
||||
pathRet = fs::path(pszHome);
|
||||
#ifdef MAC_OSX
|
||||
// Mac
|
||||
// macOS
|
||||
return pathRet / "Library/Application Support/DashCore";
|
||||
#else
|
||||
// Unix
|
||||
// Unix-like
|
||||
return pathRet / ".dashcore";
|
||||
#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;
|
||||
@ -744,6 +757,7 @@ const fs::path &GetBlocksDir()
|
||||
path /= BaseParams().DataDir();
|
||||
path /= "blocks";
|
||||
fs::create_directories(path);
|
||||
path = StripRedundantLastElementsOfPath(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
@ -774,6 +788,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
|
||||
fs::create_directories(path / "wallets");
|
||||
}
|
||||
|
||||
path = StripRedundantLastElementsOfPath(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user