utils and libraries: Replace deprecated Boost Filesystem functions #15880

pull hebasto wants to merge 2 commits into bitcoin:master from hebasto:20190423-boost-coding-guidelines changing 3 files +2 −8
  1. hebasto commented at 6:26 PM on April 23, 2019: member

    Boost Filesystem basename() and extension() functions are deprecated since v1.36.0.

    See more: https://lists.boost.org/Archives/boost/2010/01/160905.php

    Also this PR prevents further use of deprecated Boost Filesystem functions. Ref: https://www.boost.org/doc/libs/1_64_0/libs/filesystem/doc/index.htm#Coding-guidelines

    Note: On my Linux system Boost 1.65.1 header /usr/include/boost/filesystem/convenience.hpp contains:

    # ifndef BOOST_FILESYSTEM_NO_DEPRECATED
    
        inline std::string extension(const path & p)
        {
          return p.extension().string();
        }
    
        inline std::string basename(const path & p)
        {
          return p.stem().string();
        }
    
        inline path change_extension( const path & p, const path & new_extension )
        { 
          path new_p( p );
          new_p.replace_extension( new_extension );
          return new_p;
        }
    
    # endif
    

    UPDATE: Also removed unused code as noted by ryanofsky.

  2. DrahtBot added the label UTXO Db and Indexes on Apr 23, 2019
  3. DrahtBot added the label Wallet on Apr 23, 2019
  4. in src/wallet/db.cpp:411 in e5ce5a1443 outdated
     407 | @@ -408,8 +408,8 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, std::string& er
     408 |      LogPrintf("Using wallet %s\n", file_path.string());
     409 |  
     410 |      // Wallet file must be a plain filename without a directory
     411 | -    if (walletFile != fs::basename(walletFile) + fs::extension(walletFile))
     412 | -    {
     413 | +    fs::path wallet_file_path = fs::path(walletFile);
    


    Empact commented at 10:46 PM on April 28, 2019:

    nit: could construct directly


    hebasto commented at 7:10 AM on April 29, 2019:

    @Empact Thank you for your review. I'm not sure if I understand your comment correctly. Could you elaborate, please?


    Empact commented at 8:36 AM on April 29, 2019:
    -fs::path wallet_file_path = fs::path(walletFile);
    +fs::path wallet_file_path(walletFile);
    

    hebasto commented at 8:56 AM on April 29, 2019:

    Thank you! Fixed.

  5. hebasto force-pushed on Apr 29, 2019
  6. in src/wallet/db.cpp:412 in 8823a11988 outdated
     407 | @@ -408,8 +408,8 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, std::string& er
     408 |      LogPrintf("Using wallet %s\n", file_path.string());
     409 |  
     410 |      // Wallet file must be a plain filename without a directory
     411 | -    if (walletFile != fs::basename(walletFile) + fs::extension(walletFile))
     412 | -    {
     413 | +    fs::path wallet_file_path(walletFile);
     414 | +    if (walletFile != wallet_file_path.stem().string() + wallet_file_path.extension().string()) {
    


    ryanofsky commented at 2:25 PM on April 29, 2019:

    Should just drop this check. The way SplitWalletPath is defined this can never be false:

    https://github.com/bitcoin/bitcoin/blob/8da1aa471eb9f062c99c3134d6151961619e9da5/src/wallet/db.cpp#L66

    Also, the way stem() and extension() are defined you could replace them with a call to filename()

    if (walletFile != wallet_file_path.filename().string()) {
    

    https://www.boost.org/doc/libs/1_69_0/libs/filesystem/doc/reference.html#path-decomposition

  7. ryanofsky approved
  8. ryanofsky commented at 2:36 PM on April 29, 2019: member

    utACK 8823a11988d0d4824a44eb2f34e37632e7a0f09a

  9. hebasto force-pushed on Apr 29, 2019
  10. hebasto commented at 6:53 PM on April 29, 2019: member

    @ryanofsky Thank you for your review. Your comment has been addressed. Would you mind re-reviewing?

  11. ryanofsky approved
  12. ryanofsky commented at 7:08 PM on April 29, 2019: member

    utACK 276a67490f795429c1af844966ad7960908576c0. Only change is replacing impossible to reach condition with an assert.

  13. in src/wallet/db.cpp:411 in 276a67490f outdated
     407 | @@ -408,11 +408,7 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, std::string& er
     408 |      LogPrintf("Using wallet %s\n", file_path.string());
     409 |  
     410 |      // Wallet file must be a plain filename without a directory
     411 | -    if (walletFile != fs::basename(walletFile) + fs::extension(walletFile))
     412 | -    {
     413 | -        errorStr = strprintf(_("Wallet %s resides outside wallet directory %s"), walletFile, walletDir.string());
     414 | -        return false;
     415 | -    }
     416 | +    assert(walletFile == fs::path(walletFile).filename().string());
    


    promag commented at 9:18 PM on April 29, 2019:

    Suggestion, either drop the assertion (GetWalletEnv always returns a plain filename) or make it complete because:

    std::cout << path("/").filename();            // outputs "/"
    std::cout << path(".").filename();            // outputs "."
    std::cout << path("..").filename();           // outputs ".."
    

    so for these cases the assertion passes.

  14. promag commented at 9:22 PM on April 29, 2019: member

    utACK 276a674.

    Shouldn't 3edc71674ce79d81f4c5da94663787899f123719 be after 276a67490f795429c1af844966ad7960908576c0?

  15. Remove dead code for walletFile check
    SplitWalletPath() garanties the walletFile is a plain filename without a
    directory.
    4f65af97b4
  16. hebasto force-pushed on Apr 29, 2019
  17. hebasto commented at 9:58 PM on April 29, 2019: member

    @promag thank you for your review.

    Your comments have been addressed:

    • the assertion has been dropped
    • commits have been rearranged
  18. promag commented at 10:45 PM on April 29, 2019: member

    utACK 8d0add4.

  19. Empact commented at 6:35 AM on April 30, 2019: member

    utACK https://github.com/bitcoin/bitcoin/pull/15880/commits/8d0add4ea92b148e5ab8295e9fa9b6776db38c18 could squash the latter two

    The test was introduced in #7691 fyi, seems fine to remove.

  20. Replace deprecated Boost Filesystem function
    Boost Filesystem basename() function is deprecated since v1.36.0.
    Also, defining BOOST_FILESYSTEM_NO_DEPRECATED before including
    filesystem headers is strongly recommended. This prevents inadvertent
    use of old features, particularly legacy function names, that have been
    replaced and are going to go away in the future.
    a0a222eec0
  21. hebasto force-pushed on Apr 30, 2019
  22. hebasto commented at 7:11 AM on April 30, 2019: member

    @Empact

    utACK 8d0add4 could squash the latter two

    Done.

    The test was introduced in #7691 fyi, seems fine to remove.

    I guess it was earlier in #1889 ;)

  23. Empact commented at 7:43 AM on April 30, 2019: member
  24. ryanofsky approved
  25. ryanofsky commented at 4:20 PM on May 7, 2019: member

    utACK a0a222eec0b7f615a756e5e0dcec9b02296f999c. Only change is dropping assert and squashing first two commits.

  26. practicalswift commented at 4:28 PM on May 7, 2019: contributor

    utACK a0a222eec0b7f615a756e5e0dcec9b02296f999c

  27. fanquake commented at 12:57 AM on May 8, 2019: member

    utACK a0a222e

  28. meshcollider merged this on May 8, 2019
  29. meshcollider closed this on May 8, 2019

  30. meshcollider referenced this in commit ef802ef5d6 on May 8, 2019
  31. sidhujag referenced this in commit 7cef145d9b on May 8, 2019
  32. hebasto deleted the branch on May 9, 2019
  33. jasonbcox referenced this in commit e5825c36d5 on Sep 4, 2020
  34. PastaPastaPasta referenced this in commit 807daabd16 on Jun 27, 2021
  35. PastaPastaPasta referenced this in commit 7d4b40fc19 on Jun 28, 2021
  36. PastaPastaPasta referenced this in commit 6a899d3102 on Jun 29, 2021
  37. PastaPastaPasta referenced this in commit 2e8260f144 on Jul 1, 2021
  38. PastaPastaPasta referenced this in commit e2a4e1b3fd on Jul 1, 2021
  39. PastaPastaPasta referenced this in commit 18a68249f9 on Jul 8, 2021
  40. PastaPastaPasta referenced this in commit 037830d21f on Jul 10, 2021
  41. DrahtBot locked this on Dec 16, 2021

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-18 09:14 UTC

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