Issue 60634
Summary libc++ : std::filesystem::create_directories report failure when working for path with trailing '/'
Labels
Assignees
Reporter Keenuts
    Hello! Hope this is the correct process to report a libc++ issue 😊

Issue:
`std::filesystem::create_directories("/tmp/toto/")` returns a failure, even when succeeding.
>From strace, I can see the lib implem considers `/tmp/toto` to be different than `/tmp/toto/` (2 mkdir, 2 stat).

It does `mkdir("/tmp/toto/")`, which passes, then `mkdir("/tmp/toto")` which failed (directory exists).

Behavior observed at head (58927e9931219387895b4ef67ebb50eafa2d9056) on linux.

test code:
```cpp
#include <iostream>
#include <filesystem>

int main() {
  std::filesystem::path path("/tmp/toto/");
  if (std::filesystem::exists(path)) {
    std::cout << "folder exists, cannot reproduce bug. remove /tmp/toto" << std::endl;
    return 0;
  }

  std::cout << "reproducing..." << std::endl;
  if (std::filesystem::create_directories(path)) {
    std::cout << "folder was created, no bug." << std::endl;
    return 0;
  }

  std::cout << "folder was created, but failed to create it, bug." << std::endl;
  return -1;
}
```

- clone llvm-project
- configure:
```
cmake ./llvm -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS='clang' -DLLVM_TARGETS_TO_BUILD='X86;AMDGPU' -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD='DirectX;SPIRV' -DLLVM_OPTIMIZED_TABLEGEN=1 -DLLVM_ENABLE_LLD=1 -DLLVM_USE_SPLIT_DWARF=1 -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_INSTALL_PREFIX=run -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind"
```
- build
```
ninja -C build
```

- run
```
llvm-project/build/bin/clang-17 -std=c++20 test.cc -o test -stdlib=libc++ -Lllvm-project/build/lib/x86_64-unknown-linux-gnu/ -lc++ -lc++abi -lunwind -static
```

Expected output:
```
./test-bugfree
reproducing...
folder was created, no bug.
```

Observed output:
```
./test
reproducing...
folder was created, but failed to create it, bug.
```


The bug-free version is using GCC's standard lib.
This might be a known behavior difference between both libs, but this behavior clearly feels wrong from an user point of view:
```
exists("/tmp/toto/") -> false
create_directories("/tmp/toto/") -> false
exists("/tmp/toto/") -> true
```

Thanks!
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to