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 {
42
42
43
43
BOOST_FIXTURE_TEST_SUITE (util_tests, BasicTestingSetup)
44
44
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
+
45
67
BOOST_AUTO_TEST_CASE (util_check)
46
68
{
47
69
// Check that Assert can forward
Original file line number Diff line number Diff line change 34
34
#endif // __linux__
35
35
36
36
#include < algorithm>
37
+ #include < cassert>
37
38
#include < fcntl.h>
38
39
#include < sched.h>
39
40
#include < sys/resource.h>
@@ -665,6 +666,19 @@ fs::path GetDefaultDataDir()
665
666
#endif
666
667
}
667
668
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
+
668
682
static fs::path g_blocks_path_cache_net_specific;
669
683
static fs::path pathCached;
670
684
static fs::path pathCachedNetSpecific;
@@ -692,6 +706,7 @@ const fs::path &GetBlocksDir()
692
706
path /= BaseParams ().DataDir ();
693
707
path /= " blocks" ;
694
708
fs::create_directories (path);
709
+ path = StripRedundantLastElementsOfPath (path);
695
710
return path;
696
711
}
697
712
@@ -722,6 +737,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
722
737
fs::create_directories (path / " wallets" );
723
738
}
724
739
740
+ path = StripRedundantLastElementsOfPath (path);
725
741
return path;
726
742
}
727
743
You can’t perform that action at this time.
0 commit comments