Skip to content

Commit 2443cf2

Browse files
authored
Rollup merge of #96234 - goffrie:eloop, r=thomcc
remove_dir_all_recursive: treat ELOOP the same as ENOTDIR On older Linux kernels (I tested on 4.4, corresponding to Ubuntu 16.04), opening a symlink using `O_DIRECTORY | O_NOFOLLOW` returns `ELOOP` instead of `ENOTDIR`. We should handle it the same, since a symlink is still not a directory and needs to be `unlink`ed.
2 parents 41235ef + cff3f1e commit 2443cf2

File tree

1 file changed

+2
-1
lines changed
  • library/std/src/sys/unix

1 file changed

+2
-1
lines changed

library/std/src/sys/unix/fs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1647,8 +1647,9 @@ mod remove_dir_impl {
16471647
fn remove_dir_all_recursive(parent_fd: Option<RawFd>, path: &CStr) -> io::Result<()> {
16481648
// try opening as directory
16491649
let fd = match openat_nofollow_dironly(parent_fd, &path) {
1650-
Err(err) if err.raw_os_error() == Some(libc::ENOTDIR) => {
1650+
Err(err) if matches!(err.raw_os_error(), Some(libc::ENOTDIR | libc::ELOOP)) => {
16511651
// not a directory - don't traverse further
1652+
// (for symlinks, older Linux kernels may return ELOOP instead of ENOTDIR)
16521653
return match parent_fd {
16531654
// unlink...
16541655
Some(parent_fd) => {

0 commit comments

Comments
 (0)