Navigation Menu

Skip to content

Commit

Permalink
fixup! wallet: Ignore recursive_directory_iterator errors in ListWall…
Browse files Browse the repository at this point in the history
…etDir
  • Loading branch information
promag committed Mar 13, 2019
1 parent 4c61be6 commit d595965
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/wallet/walletutil.cpp
Expand Up @@ -4,6 +4,7 @@

#include <wallet/walletutil.h>

#include <logging.h>
#include <util/system.h>

fs::path GetWalletDir()
Expand Down Expand Up @@ -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;
Expand All @@ -54,11 +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;
// Use noexcept members of boost::filesystem::recursive_directory_iterator
// in order to ignore errors like `Permission denied`.
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;
}

// 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);
Expand Down

0 comments on commit d595965

Please sign in to comment.