aboutsummaryrefslogtreecommitdiff
path: root/src/util/system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/system.cpp')
-rw-r--r--src/util/system.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp
index b6a7f3926d..702397ec3b 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -29,6 +29,7 @@
#endif // __linux__
#include <algorithm>
+#include <cassert>
#include <fcntl.h>
#include <sched.h>
#include <sys/resource.h>
@@ -555,10 +556,9 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
fs::path GetDefaultDataDir()
{
- // Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin
- // Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin
- // Mac: ~/Library/Application Support/Bitcoin
- // Unix: ~/.bitcoin
+ // Windows: C:\Users\Username\AppData\Roaming\Bitcoin
+ // macOS: ~/Library/Application Support/Bitcoin
+ // Unix-like: ~/.bitcoin
#ifdef WIN32
// Windows
return GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";
@@ -570,15 +570,28 @@ fs::path GetDefaultDataDir()
else
pathRet = fs::path(pszHome);
#ifdef MAC_OSX
- // Mac
+ // macOS
return pathRet / "Library/Application Support/Bitcoin";
#else
- // Unix
+ // Unix-like
return pathRet / ".bitcoin";
#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 pathCached;
static fs::path pathCachedNetSpecific;
@@ -606,6 +619,7 @@ const fs::path &GetBlocksDir()
path /= BaseParams().DataDir();
path /= "blocks";
fs::create_directories(path);
+ path = StripRedundantLastElementsOfPath(path);
return path;
}
@@ -636,6 +650,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
fs::create_directories(path / "wallets");
}
+ path = StripRedundantLastElementsOfPath(path);
return path;
}