test: Check error for non-existent directory symlink #24432

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2202-testWin-🍀 changing 2 files +22 −1
  1. MarcoFalke commented at 4:22 PM on February 23, 2022: member

    Add a test for the case where the symlink points to a non-existing directory. This confirms the behaviour is identical to the one in v22.0 (using boost):

     node0 stderr ************************
    EXCEPTION: N5boost10filesystem16filesystem_errorE       
    boost::filesystem::create_directory: File exists: "/tmp/bitcoin_func_test_jozyx4wp/node0/regtest/blocks"       
    bitcoin in AppInit() 
    
  2. fanquake added this to the milestone 23.0 on Feb 23, 2022
  3. MarcoFalke removed this from the milestone 23.0 on Feb 23, 2022
  4. laanwj added the label Tests on Feb 23, 2022
  5. MarcoFalke marked this as a draft on Feb 23, 2022
  6. MarcoFalke commented at 6:03 PM on February 23, 2022: member

    The unit test fails, due to a bug in libc++11 and lower:

    error: in "fs_tests/create_directories": exception fs::filesystem_error expected but not raised
    
  7. MarcoFalke marked this as ready for review on Feb 23, 2022
  8. test: Check error for non-existent directory symlink fa47f9db47
  9. MarcoFalke force-pushed on Feb 23, 2022
  10. MarcoFalke commented at 6:08 PM on February 23, 2022: member

    I've commented out the failing test for now

  11. luke-jr commented at 10:42 PM on March 7, 2022: member

    Prefer to actually workaround the bug...? Can't we easily check for it and error on our own?

  12. MarcoFalke commented at 9:09 AM on March 8, 2022: member

    It might be possible, but this can be done in a follow-up

  13. luke-jr commented at 6:06 AM on March 11, 2022: member

    Well, I can't reproduce the bug (w/ Clang and libc++ 11.0 or 11.1), but this should workaround it:

    diff --git a/src/fs.h b/src/fs.h
    index 00b786453c4..c4cd5cd2a28 100644
    --- a/src/fs.h
    +++ b/src/fs.h
    @@ -13,6 +13,7 @@
     #include <ios>
     #include <ostream>
     #include <string>
    +#include <system_error>
     #include <utility>
     
     /** Filesystem operations and types */
    @@ -149,8 +150,12 @@ static inline path PathFromString(const std::string& string)
      */
     static inline bool create_directories(const std::filesystem::path& p)
     {
    -    if (std::filesystem::is_symlink(p) && std::filesystem::is_directory(p)) {
    -        return false;
    +    if (std::filesystem::is_symlink(p)) {
    +        if (std::filesystem::is_directory(p)) {
    +            return false;
    +        } else if (!std::filesystem::exists(p)) {
    +            throw std::filesystem::filesystem_error("cannot create directories", p, std::make_error_code(std::errc::not_a_directory));
    +        }
         }
         return std::filesystem::create_directories(p);
     }
    
    
  14. MarcoFalke closed this on Jun 10, 2022

  15. MarcoFalke deleted the branch on Jun 10, 2022
  16. in src/test/fs_tests.cpp:180 in fa47f9db47
     176 | +    BOOST_CHECK(!fs::exists(symlink));
     177 | +    BOOST_CHECK(fs::is_symlink(symlink));
     178 | +    BOOST_CHECK(!fs::is_directory(symlink));
     179 | +    // Next check is disabled due to a bug in libc++-11
     180 | +    // See https://github.com/bitcoin/bitcoin/pull/24432#issuecomment-1049060318
     181 | +    // BOOST_CHECK_THROW(fs::create_directories(symlink), fs::filesystem_error);
    


    MarcoFalke commented at 7:12 AM on June 10, 2022:

    for reference, the bug still exists and can be reproduced on (for example) Ubuntu Jammy clang-11:

    # clang-11 --version 
    Ubuntu clang version 11.1.0-6
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
    
    # ./src/test/test_bitcoin -t fs_tests
    Running 5 test cases...
    test/fs_tests.cpp(180): error: in "fs_tests/create_directories": exception fs::filesystem_error expected but not raised
    
    *** 1 failure is detected in the test module "Bitcoin Core Test Suite"
    
  17. DrahtBot locked this on Jun 10, 2023
Contributors
Labels

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-17 06:14 UTC

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