diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-10-16 18:06:14 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-10-27 21:45:32 +0200 |
commit | b19e88230f0e93e95e883e65376963cb9c36f606 (patch) | |
tree | d50c41eec352973eccc262981958d8dbc1802aaf /src/util/system.cpp | |
parent | 9e8d2bd076d78ba59abceb80106f44fe26246b14 (diff) |
util: Add StripRedundantLastElementsOfPath function
Co-authored-by: saibato <saibato.naga@pm.me>
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
Diffstat (limited to 'src/util/system.cpp')
-rw-r--r-- | src/util/system.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
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 <algorithm> +#include <cassert> #include <fcntl.h> #include <sched.h> #include <sys/resource.h> @@ -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; } |