aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-06-23 16:15:50 -0400
committerAndrew Chow <github@achow101.com>2023-06-23 16:21:43 -0400
commit2c2150aa04b86d65d5545d3401a12046375b584d (patch)
treecc8fcbeb329c7bdcdca200e3908ff5943e4792ea /src
parent6a473373d4953cabbb219eae8b709150a45796e6 (diff)
parent0e21b56a44d53cec9080edb04410a692717f1ddc (diff)
downloadbitcoin-2c2150aa04b86d65d5545d3401a12046375b584d.tar.xz
Merge bitcoin/bitcoin#26828: assumeutxo: catch and log fs::remove error instead of two exist checks
0e21b56a44d53cec9080edb04410a692717f1ddc assumeutxo: catch and log fs::remove error instead of two exist checks (Andrew Toth) Pull request description: Fixes a block of code which seems to be incorrectly performing two existence checks instead of catching and logging errors. `fs::remove` returns `false` only if the file being removed does not exist, so it is redundant with the `fs::exists` check. If an error does occur when trying to remove an existing file, `fs::remove` will throw. See https://en.cppreference.com/w/cpp/filesystem/remove. Also see https://github.com/bitcoin/bitcoin/blob/master/src/init.cpp#L326-L332 for a similar pattern. ACKs for top commit: MarcoFalke: lgtm ACK 0e21b56a44d53cec9080edb04410a692717f1ddc jamesob: ACK https://github.com/bitcoin/bitcoin/pull/26828/commits/0e21b56a44d53cec9080edb04410a692717f1ddc achow101: ACK 0e21b56a44d53cec9080edb04410a692717f1ddc Tree-SHA512: 137d0be5266cfd947e5e50ec93b895ac659adadf9413bef3468744bfdacee8dbe7d9bdfaf91784c45708610325d2241a114f4be4e622a108a639b3672b618fd2
Diffstat (limited to 'src')
-rw-r--r--src/validation.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index 1fd20ca2c8..6836498a64 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4999,15 +4999,15 @@ static bool DeleteCoinsDBFromDisk(const fs::path db_path, bool is_snapshot)
if (is_snapshot) {
fs::path base_blockhash_path = db_path / node::SNAPSHOT_BLOCKHASH_FILENAME;
- if (fs::exists(base_blockhash_path)) {
- bool removed = fs::remove(base_blockhash_path);
- if (!removed) {
- LogPrintf("[snapshot] failed to remove file %s\n",
- fs::PathToString(base_blockhash_path));
+ try {
+ bool existed = fs::remove(base_blockhash_path);
+ if (!existed) {
+ LogPrintf("[snapshot] snapshot chainstate dir being removed lacks %s file\n",
+ fs::PathToString(node::SNAPSHOT_BLOCKHASH_FILENAME));
}
- } else {
- LogPrintf("[snapshot] snapshot chainstate dir being removed lacks %s file\n",
- fs::PathToString(node::SNAPSHOT_BLOCKHASH_FILENAME));
+ } catch (const fs::filesystem_error& e) {
+ LogPrintf("[snapshot] failed to remove file %s: %s\n",
+ fs::PathToString(base_blockhash_path), fsbridge::get_filesystem_error_message(e));
}
}