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:
Hodlinator
2025-06-13 13:41:59 +02:00
parent 5757de4ddd
commit 893e51ffeb

View File

@@ -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;
}