mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-09 11:21:15 +02:00
util: Add StripRedundantLastElementsOfPath function
Co-authored-by: saibato <saibato.naga@pm.me> Co-authored-by: MarcoFalke <falke.marco@gmail.com>
This commit is contained in:
parent
9e8d2bd076
commit
b19e88230f
@ -42,6 +42,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());
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(util_check)
|
BOOST_AUTO_TEST_CASE(util_check)
|
||||||
{
|
{
|
||||||
// Check that Assert can forward
|
// Check that Assert can forward
|
||||||
|
@ -34,6 +34,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>
|
||||||
@ -665,6 +666,19 @@ fs::path GetDefaultDataDir()
|
|||||||
#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;
|
||||||
@ -692,6 +706,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,6 +737,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…
x
Reference in New Issue
Block a user