mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
Merge bitcoin/bitcoin#26828: assumeutxo: catch and log fs::remove error instead of two exist checks
0e21b56a44
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 ACK0e21b56a44
jamesob: ACK0e21b56a44
achow101: ACK0e21b56a44
Tree-SHA512: 137d0be5266cfd947e5e50ec93b895ac659adadf9413bef3468744bfdacee8dbe7d9bdfaf91784c45708610325d2241a114f4be4e622a108a639b3672b618fd2
This commit is contained in:
commit
2c2150aa04
1 changed files with 8 additions and 8 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue