From b19e88230f0e93e95e883e65376963cb9c36f606 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:06:14 +0300 Subject: util: Add StripRedundantLastElementsOfPath function Co-authored-by: saibato Co-authored-by: MarcoFalke --- src/util/system.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/util') diff --git a/src/util/system.cpp b/src/util/system.cpp index a411b73a16..7754ef3e01 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -34,6 +34,7 @@ #endif // __linux__ #include +#include #include #include #include @@ -665,6 +666,19 @@ fs::path GetDefaultDataDir() #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; @@ -692,6 +706,7 @@ const fs::path &GetBlocksDir() path /= BaseParams().DataDir(); path /= "blocks"; fs::create_directories(path); + path = StripRedundantLastElementsOfPath(path); return path; } @@ -722,6 +737,7 @@ const fs::path &GetDataDir(bool fNetSpecific) fs::create_directories(path / "wallets"); } + path = StripRedundantLastElementsOfPath(path); return path; } -- cgit v1.2.3 From ad5cef5dfdd5802fc187a52e74d940a52f420a51 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:32:43 +0300 Subject: doc: Update data directory path comments --- src/util/system.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/util') diff --git a/src/util/system.cpp b/src/util/system.cpp index 7754ef3e01..a3f21f0162 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -642,10 +642,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"; @@ -657,10 +656,10 @@ 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 -- cgit v1.2.3