3535#endif // __linux__
3636
3737#include < algorithm>
38+ #include < cassert>
3839#include < fcntl.h>
3940#include < sched.h>
4041#include < sys/resource.h>
@@ -687,10 +688,9 @@ void PrintExceptionContinue(const std::exception_ptr pex, const char* pszExcepti
687688
688689fs::path GetDefaultDataDir ()
689690{
690- // Windows < Vista: C:\Documents and Settings\Username\Application Data\DashCore
691- // Windows >= Vista: C:\Users\Username\AppData\Roaming\DashCore
692- // Mac: ~/Library/Application Support/DashCore
693- // Unix: ~/.dashcore
691+ // Windows: C:\Users\Username\AppData\Roaming\DashCore
692+ // macOS: ~/Library/Application Support/DashCore
693+ // Unix-like: ~/.dashcore
694694#ifdef WIN32
695695 // Windows
696696 return GetSpecialFolderPath (CSIDL_APPDATA) / " DashCore" ;
@@ -702,15 +702,28 @@ fs::path GetDefaultDataDir()
702702 else
703703 pathRet = fs::path (pszHome);
704704#ifdef MAC_OSX
705- // Mac
705+ // macOS
706706 return pathRet / " Library/Application Support/DashCore" ;
707707#else
708- // Unix
708+ // Unix-like
709709 return pathRet / " .dashcore" ;
710710#endif
711711#endif
712712}
713713
714+ namespace {
715+ fs::path StripRedundantLastElementsOfPath (const fs::path& path)
716+ {
717+ auto result = path;
718+ while (result.filename ().string () == " ." ) {
719+ result = result.parent_path ();
720+ }
721+
722+ assert (fs::equivalent (result, path));
723+ return result;
724+ }
725+ } // namespace
726+
714727static fs::path g_blocks_path_cache_net_specific;
715728static fs::path pathCached;
716729static fs::path pathCachedNetSpecific;
@@ -738,6 +751,7 @@ const fs::path &GetBlocksDir()
738751 path /= BaseParams ().DataDir ();
739752 path /= " blocks" ;
740753 fs::create_directories (path);
754+ path = StripRedundantLastElementsOfPath (path);
741755 return path;
742756}
743757
@@ -768,6 +782,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
768782 fs::create_directories (path / " wallets" );
769783 }
770784
785+ path = StripRedundantLastElementsOfPath (path);
771786 return path;
772787}
773788
0 commit comments