From cff3f1e8d52a1bd6340362cbe7689dd6fa4f72e1 Mon Sep 17 00:00:00 2001 From: Geoffry Song Date: Wed, 20 Apr 2022 00:46:50 +0000 Subject: [PATCH] remove_dir_all_recursive: treat ELOOP the same as ENOTDIR --- library/std/src/sys/unix/fs.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 7181451de57..a60b19976ba 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -1647,8 +1647,9 @@ fn is_dir(ent: &DirEntry) -> Option { fn remove_dir_all_recursive(parent_fd: Option, path: &CStr) -> io::Result<()> { // try opening as directory let fd = match openat_nofollow_dironly(parent_fd, &path) { - Err(err) if err.raw_os_error() == Some(libc::ENOTDIR) => { + Err(err) if matches!(err.raw_os_error(), Some(libc::ENOTDIR | libc::ELOOP)) => { // not a directory - don't traverse further + // (for symlinks, older Linux kernels may return ELOOP instead of ENOTDIR) return match parent_fd { // unlink... Some(parent_fd) => {