Skip to content

std::fs::remove_dir_all doesn't handle paths that are too long #53339

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
drrlvn opened this issue Aug 14, 2018 · 1 comment
Open

std::fs::remove_dir_all doesn't handle paths that are too long #53339

drrlvn opened this issue Aug 14, 2018 · 1 comment
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. O-linux Operating system: Linux T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@drrlvn
Copy link
Contributor

drrlvn commented Aug 14, 2018

On Linux unlink() might fail with ENAMETOOLONG but std::fs::remove_dir_all doesn't handle that and ignores the error, leaving the directory as it was.

When the path is too long a parent directory should be open()ed instead and unlinkat() should be called with the relative path.

@retep998 retep998 added O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Aug 14, 2018
@the8472
Copy link
Member

the8472 commented Aug 17, 2018

It would be best to always use openat, otherwise there could be a race where the target directory is swapped with a symlink to some other directory and it then tries to delete descendants of the swapped one.

@Enselic Enselic added C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue. A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 28, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. O-linux Operating system: Linux T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants