about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHans Kratz <hans@appfour.com>2022-01-20 12:35:16 +0100
committerPietro Albini <pietro.albini@ferrous-systems.com>2022-01-20 12:38:48 +0100
commitcb88166762d30dfc6f7d57679755e79ba5676f4c (patch)
tree22710f9adee7d868b4fad8a7f6d42ebd01b0a1be
parent1e17daf1e0104ef096f70c062dd92e4310cd2966 (diff)
downloadrust-cb88166762d30dfc6f7d57679755e79ba5676f4c.tar.gz
rust-cb88166762d30dfc6f7d57679755e79ba5676f4c.zip
backport missed illumos fix
-rw-r--r--library/std/src/sys/unix/fs.rs43
1 files changed, 26 insertions, 17 deletions
diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
index a150d1a9aac..ca7f132a8b3 100644
--- a/library/std/src/sys/unix/fs.rs
+++ b/library/std/src/sys/unix/fs.rs
@@ -1582,7 +1582,7 @@ mod remove_dir_impl {
 // Modern implementation using openat(), unlinkat() and fdopendir()
 #[cfg(not(any(all(target_os = "macos", target_arch = "x86_64"), target_os = "redox")))]
 mod remove_dir_impl {
-    use super::{cstr, lstat, Dir, InnerReadDir, ReadDir};
+    use super::{cstr, lstat, Dir, DirEntry, InnerReadDir, ReadDir};
     use crate::ffi::CStr;
     use crate::io;
     use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
@@ -1629,6 +1629,30 @@ mod remove_dir_impl {
         ))
     }
 
+    #[cfg(any(
+        target_os = "solaris",
+        target_os = "illumos",
+        target_os = "haiku",
+        target_os = "vxworks"
+    ))]
+    fn is_dir(_ent: &DirEntry) -> Option<bool> {
+        None
+    }
+
+    #[cfg(not(any(
+        target_os = "solaris",
+        target_os = "illumos",
+        target_os = "haiku",
+        target_os = "vxworks"
+    )))]
+    fn is_dir(ent: &DirEntry) -> Option<bool> {
+        match ent.entry.d_type {
+            libc::DT_UNKNOWN => None,
+            libc::DT_DIR => Some(true),
+            _ => Some(false),
+        }
+    }
+
     fn remove_dir_all_recursive(parent_fd: Option<RawFd>, p: &Path) -> io::Result<()> {
         let pcstr = cstr(p)?;
 
@@ -1639,22 +1663,7 @@ mod remove_dir_impl {
         let (dir, fd) = fdreaddir(fd)?;
         for child in dir {
             let child = child?;
-            let child_is_dir = if cfg!(any(
-                target_os = "solaris",
-                target_os = "illumos",
-                target_os = "haiku",
-                target_os = "vxworks"
-            )) {
-                // no d_type in dirent
-                None
-            } else {
-                match child.entry.d_type {
-                    libc::DT_UNKNOWN => None,
-                    libc::DT_DIR => Some(true),
-                    _ => Some(false),
-                }
-            };
-            match child_is_dir {
+            match is_dir(&child) {
                 Some(true) => {
                     remove_dir_all_recursive(Some(fd), Path::new(&child.file_name()))?;
                 }