https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118003
Bug ID: 118003
Summary: std::filesystem::remove_all() hangs on Windows on
directories containing a deep tree with long paths
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: martin at martin dot st
Target Milestone: ---
To reproduce - create a deep tree where the total path name to the deepest
folders exceed the normal MAX_PATH. E.g. in msys2, do this:
$ mkdir -p
/tmp/file-system-test-ed4fa1/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss/DirNameWith19Charss
Then build the following test program, that tries to remove this directory
tree:
#include <filesystem>
#include <iostream>
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cout << argv[0] << " dir" << std::endl;
return 0;
}
std::filesystem::path Path(argv[1]);
std::error_code EC;
std::cout << "Path " << Path << std::endl;
std::filesystem::remove_all(Path, EC);
return 0;
}
Running this in msys2 like this:
$ ./fs-removeall.exe /tmp/file-system-test-ed4fa1
Path "C:/msys64/tmp/file-system-test-ed4fa1"
At this point, the program hangs, and doesn't complete. If we remove one level
of directories, so that the deepest point of the directory tree no longer
exceeds MAX_PATH, the program succeeds.
This situation was observed in an LLVM test, when attempting to use
std::filesystem::remove_all() for such operations, in
https://github.com/llvm/llvm-project/pull/119146.
The same operation succeeds with libc++ and MS STL.