gulrak / filesystem

An implementation of C++17 std::filesystem for C++11 /C++14/C++17/C++20 on Windows, macOS, Linux and FreeBSD.
MIT License
1.31k stars 168 forks source link

recursive_directory_iterator for error symlink #178

Open Layty opened 6 months ago

Layty commented 6 months ago

Describe the bug I want to get a floder size, like du -s but in a floder, there is a error symlink file like a loop

cd /tmp
ln -sf abc abc

then use fs::recursive_directory_iterator will report

Error occurred while calculating file size: Too many levels of symbolic links: '/tmp/abc'

To Reproduce Detailed steps to reproduce the behavior.

Expected behavior I think we can check it is a bad file ?

gulrak commented 6 months ago

While it would not solve the issue of longer loops (linking a few levels up the path) detecting such self-links might be something cheap enough to make it a feature. I'll think about a solution.