Skip to content

Commit 893e51f

Browse files
committed
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.
1 parent 5757de4 commit 893e51f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/wallet/db.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,7 @@ std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wall
2626
std::error_code ec;
2727

2828
for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
29-
if (ec) {
30-
if (fs::is_directory(*it)) {
31-
it.disable_recursion_pending();
32-
LogPrintf("%s: %s %s -- skipping.\n", __func__, ec.message(), fs::PathToString(it->path()));
33-
} else {
34-
LogPrintf("%s: %s %s\n", __func__, ec.message(), fs::PathToString(it->path()));
35-
}
36-
continue;
37-
}
38-
29+
assert(!ec); // Loop should exit on error.
3930
try {
4031
const fs::path path{it->path().lexically_relative(wallet_dir)};
4132

@@ -69,6 +60,14 @@ std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wall
6960
it.disable_recursion_pending();
7061
}
7162
}
63+
if (ec) {
64+
// Loop could have exited with an error due to one of:
65+
// * wallet_dir itself not being scannable.
66+
// * increment() failure. (Observed on Windows native builds when
67+
// removing the ACL read permissions of a wallet directory after the
68+
// process started).
69+
LogWarning("Error scanning directory entries under %s: %s", fs::PathToString(wallet_dir), ec.message());
70+
}
7271

7372
return paths;
7473
}

0 commit comments

Comments
 (0)