aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2019-03-14 18:57:32 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2019-03-14 18:58:43 +0100
commit7fa1f6258c05648f901d7135f8b6606f60428e70 (patch)
tree338f6d14ba2bb73c7f5bc6cc798b7d5abd990f0a
parent8e1704c01537d1750555de23bfae00efa5864b3e (diff)
parent15c69b158da570f4e1430280c610e94ffdee0e51 (diff)
Merge #15583: wallet: Log and ignore errors in ListWalletDir and IsBerkeleyBtree
15c69b158da570f4e1430280c610e94ffdee0e51 wallet: Log and ignore errors in ListWalletDir and IsBerkeleyBtree (João Barbosa) Pull request description: Use the `noexcept` members of `boost::filesystem::recursive_directory_iterator` in order to ignore `boost::filesystem::directory_iterator::construct: Permission denied` errors. The errors are logged though. Steps to reproduce the issue: ```sh # 1. create directory for -walletdir without read access: mkdir /tmp/foo && chmod a-r /tmp/foo # 2. run bitcoin-qt and should print an error, but continues running: /Volumes/Bitcoin-Core/Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt -regtest -walletdir=/tmp/foo /private/tmp/foo: Permission denied # 4. go to File -> Open Wallet and should segfault: EXCEPTION: N5boost10filesystem16filesystem_errorE boost::filesystem::directory_iterator::construct: Permission denied: "/private/tmp/foo" bitcoin in Runaway exception ``` Tree-SHA512: 37e8bf5a1e0defc331030fd511bf9cac2765d01dfbf23e7233f37506e85b8ad07edcde9ba6dae7a2c95700c78d28c7dd248153607381852da96273cb159c4934
-rw-r--r--src/wallet/walletutil.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/wallet/walletutil.cpp b/src/wallet/walletutil.cpp
index d779251d56..2d8adf8ba6 100644
--- a/src/wallet/walletutil.cpp
+++ b/src/wallet/walletutil.cpp
@@ -4,6 +4,7 @@
#include <wallet/walletutil.h>
+#include <logging.h>
#include <util/system.h>
fs::path GetWalletDir()
@@ -33,7 +34,9 @@ static bool IsBerkeleyBtree(const fs::path& path)
// A Berkeley DB Btree file has at least 4K.
// This check also prevents opening lock files.
boost::system::error_code ec;
- if (fs::file_size(path, ec) < 4096) return false;
+ auto size = fs::file_size(path, ec);
+ if (ec) LogPrintf("%s: %s %s\n", __func__, ec.message(), path.string());
+ if (size < 4096) return false;
fsbridge::ifstream file(path, std::ios::binary);
if (!file.is_open()) return false;
@@ -54,8 +57,14 @@ std::vector<fs::path> ListWalletDir()
const fs::path wallet_dir = GetWalletDir();
const size_t offset = wallet_dir.string().size() + 1;
std::vector<fs::path> paths;
+ boost::system::error_code ec;
+
+ for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
+ if (ec) {
+ LogPrintf("%s: %s %s\n", __func__, ec.message(), it->path().string());
+ continue;
+ }
- for (auto it = fs::recursive_directory_iterator(wallet_dir); it != fs::recursive_directory_iterator(); ++it) {
// Get wallet path relative to walletdir by removing walletdir from the wallet path.
// This can be replaced by boost::filesystem::lexically_relative once boost is bumped to 1.60.
const fs::path path = it->path().string().substr(offset);