mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-27 11:51:43 +02:00
wallet: Correct dir iteration error handling
Seems to have been broken since conversion from Boost in #20744. The std::filesystem iteration aborts upon failure while Boost might have allowed skipping over faulty entries.
This commit is contained in:
@@ -26,16 +26,7 @@ std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wall
|
||||
std::error_code ec;
|
||||
|
||||
for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
|
||||
if (ec) {
|
||||
if (fs::is_directory(*it)) {
|
||||
it.disable_recursion_pending();
|
||||
LogPrintf("%s: %s %s -- skipping.\n", __func__, ec.message(), fs::PathToString(it->path()));
|
||||
} else {
|
||||
LogPrintf("%s: %s %s\n", __func__, ec.message(), fs::PathToString(it->path()));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
assert(!ec); // Loop should exit on error.
|
||||
try {
|
||||
const fs::path path{it->path().lexically_relative(wallet_dir)};
|
||||
|
||||
@@ -69,6 +60,14 @@ std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wall
|
||||
it.disable_recursion_pending();
|
||||
}
|
||||
}
|
||||
if (ec) {
|
||||
// Loop could have exited with an error due to one of:
|
||||
// * wallet_dir itself not being scannable.
|
||||
// * increment() failure. (Observed on Windows native builds when
|
||||
// removing the ACL read permissions of a wallet directory after the
|
||||
// process started).
|
||||
LogWarning("Error scanning directory entries under %s: %s", fs::PathToString(wallet_dir), ec.message());
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
Reference in New Issue
Block a user