3535#endif // __linux__
3636
3737#include < algorithm>
38+ #include < cassert>
3839#include < fcntl.h>
3940#include < sched.h>
4041#include < sys/resource.h>
@@ -693,10 +694,9 @@ void PrintExceptionContinue(const std::exception_ptr pex, const char* pszExcepti
693694
694695fs::path GetDefaultDataDir ()
695696{
696- // Windows < Vista: C:\Documents and Settings\Username\Application Data\DashCore
697- // Windows >= Vista: C:\Users\Username\AppData\Roaming\DashCore
698- // Mac: ~/Library/Application Support/DashCore
699- // Unix: ~/.dashcore
697+ // Windows: C:\Users\Username\AppData\Roaming\DashCore
698+ // macOS: ~/Library/Application Support/DashCore
699+ // Unix-like: ~/.dashcore
700700#ifdef WIN32
701701 // Windows
702702 return GetSpecialFolderPath (CSIDL_APPDATA) / " DashCore" ;
@@ -708,15 +708,28 @@ fs::path GetDefaultDataDir()
708708 else
709709 pathRet = fs::path (pszHome);
710710#ifdef MAC_OSX
711- // Mac
711+ // macOS
712712 return pathRet / " Library/Application Support/DashCore" ;
713713#else
714- // Unix
714+ // Unix-like
715715 return pathRet / " .dashcore" ;
716716#endif
717717#endif
718718}
719719
720+ namespace {
721+ fs::path StripRedundantLastElementsOfPath (const fs::path& path)
722+ {
723+ auto result = path;
724+ while (result.filename ().string () == " ." ) {
725+ result = result.parent_path ();
726+ }
727+
728+ assert (fs::equivalent (result, path));
729+ return result;
730+ }
731+ } // namespace
732+
720733static fs::path g_blocks_path_cache_net_specific;
721734static fs::path pathCached;
722735static fs::path pathCachedNetSpecific;
@@ -744,6 +757,7 @@ const fs::path &GetBlocksDir()
744757 path /= BaseParams ().DataDir ();
745758 path /= " blocks" ;
746759 fs::create_directories (path);
760+ path = StripRedundantLastElementsOfPath (path);
747761 return path;
748762}
749763
@@ -774,6 +788,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
774788 fs::create_directories (path / " wallets" );
775789 }
776790
791+ path = StripRedundantLastElementsOfPath (path);
777792 return path;
778793}
779794
0 commit comments