aboutsummaryrefslogtreecommitdiff
path: root/src/util/system.cpp
diff options
context:
space:
mode:
authorSamuel Dobson <dobsonsa68@gmail.com>2020-11-02 11:40:57 +1300
committerSamuel Dobson <dobsonsa68@gmail.com>2020-11-02 11:41:38 +1300
commit5a6f3c5a01eaf904c42bd77dbed931b49a8fec74 (patch)
treec1720bc760aa557f3e404a3dbc065c25df7cdb3c /src/util/system.cpp
parent42b66a6b814bca130a9ccf0a3f747cf33d628232 (diff)
parentad5cef5dfdd5802fc187a52e74d940a52f420a51 (diff)
Merge #20080: Strip any trailing `/` in -datadir and -blocksdir paths
ad5cef5dfdd5802fc187a52e74d940a52f420a51 doc: Update data directory path comments (Hennadii Stepanov) b19e88230f0e93e95e883e65376963cb9c36f606 util: Add StripRedundantLastElementsOfPath function (Hennadii Stepanov) Pull request description: Wallet names in `listwalletdir` RPC are correct now, even if the `-datadir` path has any number of trailing `/`. This PR is an alternative to #19933. Fixes #19928. ACKs for top commit: MarcoFalke: review ACK ad5cef5dfd 🔙 promag: Code review ACK ad5cef5dfdd5802fc187a52e74d940a52f420a51. meshcollider: Code review + test run ACK ad5cef5dfdd5802fc187a52e74d940a52f420a51 Tree-SHA512: bccabbd6c18243d48d15b2b27201cc0f5984623dcbc635c8740cf74523f359844c36eadd40391142874fcf452a43880bb6afbf89815ae736e499f9a98143a661
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 9f8035948b..5f30136fa2 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>
@@ -649,10 +650,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";
@@ -664,15 +664,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;
@@ -700,6 +713,7 @@ const fs::path &GetBlocksDir()
path /= BaseParams().DataDir();
path /= "blocks";
fs::create_directories(path);
+ path = StripRedundantLastElementsOfPath(path);
return path;
}
@@ -730,6 +744,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
fs::create_directories(path / "wallets");
}
+ path = StripRedundantLastElementsOfPath(path);
return path;
}