Repository navigation
assumeutxo: catch and log fs::remove error instead of two exist checks - #26828
Merged
Merged
Conversation
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
andrewtoth
force-pushed
the
assumeutxo-remove-fix
branch
from
January 5, 2023 22:33
4fe7d35 to
cff2f3c
Compare
andrewtoth
force-pushed
the
assumeutxo-remove-fix
branch
from
January 5, 2023 22:35
cff2f3c to
0e21b56
Compare
Contributor
|
Approach ACK, thanks for fixing this. Will give a thorough look in the next day or two. |
brunoerg
reviewed
Jan 12, 2023
| LogPrintf("[snapshot] failed to remove file %s\n", | ||
| fs::PathToString(base_blockhash_path)); | ||
| try { | ||
| bool existed = fs::remove(base_blockhash_path); |
Contributor
There was a problem hiding this comment.
nit:
Suggested change
| bool existed = fs::remove(base_blockhash_path); | |
| const bool existed{fs::remove(base_blockhash_path)}; |
Contributor
|
ACK 0e21b56 Built locally. Makes sense, thank you for the cleanup! |
Member
|
ACK 0e21b56 |
Fabcien
pushed a commit
to Bitcoin-ABC/bitcoin-abc
that referenced
this pull request
Dec 18, 2023
Summary: 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. This is a backport of [[bitcoin/bitcoin#26828 | core#26828]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D14995
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a block of code which seems to be incorrectly performing two existence checks instead of catching and logging errors.
fs::removereturnsfalseonly if the file being removed does not exist, so it is redundant with thefs::existscheck. If an error does occur when trying to remove an existing file,fs::removewill 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.