assumeutxo: catch and log fs::remove error instead of two exist checks #26828

pull andrewtoth wants to merge 1 commits into bitcoin:master from andrewtoth:assumeutxo-remove-fix changing 1 files +8 −8
  1. andrewtoth commented at 10:25 PM on January 5, 2023: contributor

    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.

  2. DrahtBot commented at 10:25 PM on January 5, 2023: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK MarcoFalke, jamesob, achow101
    Concept ACK brunoerg, luke-jr

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. andrewtoth force-pushed on Jan 5, 2023
  4. assumeutxo: catch and log fs::remove error instead of two exist checks 0e21b56a44
  5. andrewtoth force-pushed on Jan 5, 2023
  6. fanquake requested review from jamesob on Jan 6, 2023
  7. jamesob commented at 12:16 AM on January 7, 2023: member

    Approach ACK, thanks for fixing this. Will give a thorough look in the next day or two.

  8. in src/validation.cpp:4863 in 0e21b56a44
    4863 | -            bool removed = fs::remove(base_blockhash_path);
    4864 | -            if (!removed) {
    4865 | -                LogPrintf("[snapshot] failed to remove file %s\n",
    4866 | -                          fs::PathToString(base_blockhash_path));
    4867 | +        try {
    4868 | +            bool existed = fs::remove(base_blockhash_path);
    


    brunoerg commented at 1:54 PM on January 12, 2023:

    nit:

                const bool existed{fs::remove(base_blockhash_path)};
    
  9. brunoerg commented at 1:56 PM on January 12, 2023: contributor

    Concept ACK

  10. achow101 assigned jamesob on Apr 25, 2023
  11. luke-jr approved
  12. luke-jr commented at 9:58 PM on June 21, 2023: member

    utACK (also fine with @brunoerg's nit being addressed)

  13. maflcko commented at 8:46 AM on June 22, 2023: member

    lgtm ACK 0e21b56a44d53cec9080edb04410a692717f1ddc

    No idea what the link in OP should point to, but I presume it is https://github.com/bitcoin/bitcoin/blob/fff80cd2488899a322f9e673930a00eb9ab5b165/src/init.cpp#L326-L332

  14. jamesob commented at 5:08 PM on June 22, 2023: member
  15. DrahtBot removed review request from jamesob on Jun 22, 2023
  16. achow101 commented at 8:15 PM on June 23, 2023: member

    ACK 0e21b56a44d53cec9080edb04410a692717f1ddc

  17. achow101 merged this on Jun 23, 2023
  18. achow101 closed this on Jun 23, 2023

  19. sidhujag referenced this in commit f97b346588 on Jun 25, 2023
  20. andrewtoth deleted the branch on Aug 17, 2023
  21. Fabcien referenced this in commit db99dc1ba8 on Dec 18, 2023
  22. bitcoin locked this on Aug 16, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-30 00:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me