aboutsummaryrefslogtreecommitdiff
path: root/src/util/system.cpp
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2020-10-16 18:06:14 +0300
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2020-10-27 21:45:32 +0200
commitb19e88230f0e93e95e883e65376963cb9c36f606 (patch)
treed50c41eec352973eccc262981958d8dbc1802aaf /src/util/system.cpp
parent9e8d2bd076d78ba59abceb80106f44fe26246b14 (diff)
downloadbitcoin-b19e88230f0e93e95e883e65376963cb9c36f606.tar.xz
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.cpp16
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;
}