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_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 {
|
namespace {
|
||||||
class NoCopyOrMove
|
class NoCopyOrMove
|
||||||
{
|
{
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
@ -693,10 +694,9 @@ void PrintExceptionContinue(const std::exception_ptr pex, const char* pszExcepti
|
|||||||
|
|
||||||
fs::path GetDefaultDataDir()
|
fs::path GetDefaultDataDir()
|
||||||
{
|
{
|
||||||
// Windows < Vista: C:\Documents and Settings\Username\Application Data\DashCore
|
// Windows: C:\Users\Username\AppData\Roaming\DashCore
|
||||||
// Windows >= Vista: C:\Users\Username\AppData\Roaming\DashCore
|
// macOS: ~/Library/Application Support/DashCore
|
||||||
// Mac: ~/Library/Application Support/DashCore
|
// Unix-like: ~/.dashcore
|
||||||
// Unix: ~/.dashcore
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// Windows
|
// Windows
|
||||||
return GetSpecialFolderPath(CSIDL_APPDATA) / "DashCore";
|
return GetSpecialFolderPath(CSIDL_APPDATA) / "DashCore";
|
||||||
@ -708,15 +708,28 @@ fs::path GetDefaultDataDir()
|
|||||||
else
|
else
|
||||||
pathRet = fs::path(pszHome);
|
pathRet = fs::path(pszHome);
|
||||||
#ifdef MAC_OSX
|
#ifdef MAC_OSX
|
||||||
// Mac
|
// macOS
|
||||||
return pathRet / "Library/Application Support/DashCore";
|
return pathRet / "Library/Application Support/DashCore";
|
||||||
#else
|
#else
|
||||||
// Unix
|
// Unix-like
|
||||||
return pathRet / ".dashcore";
|
return pathRet / ".dashcore";
|
||||||
#endif
|
#endif
|
||||||
#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 g_blocks_path_cache_net_specific;
|
||||||
static fs::path pathCached;
|
static fs::path pathCached;
|
||||||
static fs::path pathCachedNetSpecific;
|
static fs::path pathCachedNetSpecific;
|
||||||
@ -744,6 +757,7 @@ const fs::path &GetBlocksDir()
|
|||||||
path /= BaseParams().DataDir();
|
path /= BaseParams().DataDir();
|
||||||
path /= "blocks";
|
path /= "blocks";
|
||||||
fs::create_directories(path);
|
fs::create_directories(path);
|
||||||
|
path = StripRedundantLastElementsOfPath(path);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -774,6 +788,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
|
|||||||
fs::create_directories(path / "wallets");
|
fs::create_directories(path / "wallets");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path = StripRedundantLastElementsOfPath(path);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user