File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,28 @@ namespace BCLog {
4242
4343BOOST_FIXTURE_TEST_SUITE (util_tests, BasicTestingSetup)
4444
45+ BOOST_AUTO_TEST_CASE(util_datadir)
46+ {
47+ ClearDatadirCache ();
48+ const fs::path dd_norm = GetDataDir ();
49+
50+ gArgs .ForceSetArg (" -datadir" , dd_norm.string () + " /" );
51+ ClearDatadirCache ();
52+ BOOST_CHECK_EQUAL (dd_norm, GetDataDir ());
53+
54+ gArgs .ForceSetArg (" -datadir" , dd_norm.string () + " /." );
55+ ClearDatadirCache ();
56+ BOOST_CHECK_EQUAL (dd_norm, GetDataDir ());
57+
58+ gArgs .ForceSetArg (" -datadir" , dd_norm.string () + " /./" );
59+ ClearDatadirCache ();
60+ BOOST_CHECK_EQUAL (dd_norm, GetDataDir ());
61+
62+ gArgs .ForceSetArg (" -datadir" , dd_norm.string () + " /.//" );
63+ ClearDatadirCache ();
64+ BOOST_CHECK_EQUAL (dd_norm, GetDataDir ());
65+ }
66+
4567BOOST_AUTO_TEST_CASE (util_check)
4668{
4769 // Check that Assert can forward
Original file line number Diff line number Diff line change 3434#endif // __linux__
3535
3636#include < algorithm>
37+ #include < cassert>
3738#include < fcntl.h>
3839#include < sched.h>
3940#include < sys/resource.h>
@@ -665,6 +666,19 @@ fs::path GetDefaultDataDir()
665666#endif
666667}
667668
669+ namespace {
670+ fs::path StripRedundantLastElementsOfPath (const fs::path& path)
671+ {
672+ auto result = path;
673+ while (result.filename ().string () == " ." ) {
674+ result = result.parent_path ();
675+ }
676+
677+ assert (fs::equivalent (result, path));
678+ return result;
679+ }
680+ } // namespace
681+
668682static fs::path g_blocks_path_cache_net_specific;
669683static fs::path pathCached;
670684static fs::path pathCachedNetSpecific;
@@ -692,6 +706,7 @@ const fs::path &GetBlocksDir()
692706 path /= BaseParams ().DataDir ();
693707 path /= " blocks" ;
694708 fs::create_directories (path);
709+ path = StripRedundantLastElementsOfPath (path);
695710 return path;
696711}
697712
@@ -722,6 +737,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
722737 fs::create_directories (path / " wallets" );
723738 }
724739
740+ path = StripRedundantLastElementsOfPath (path);
725741 return path;
726742}
727743
You can’t perform that action at this time.
0 commit comments