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