From 893e51ffeb0543e1c8d33e83b20c56f02d2b793c Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Fri, 13 Jun 2025 13:41:59 +0200 Subject: [PATCH] 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. --- src/wallet/db.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 9de0572947..40692997d2 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -26,16 +26,7 @@ std::vector> 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> 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; }