Skip to content

Commit dc44e7f

Browse files
committed
Auto merge of #163552 - RalfJung:dir-entry-metadata, r=Mark-Simulacrum
DirEntry::metadata: use dirfd on more targets Most of the BSDs support `dirfd` and `fstatat` just fine but for some reason we've not been using it for `DirEntry::metadata`. This syncs the `cfg` for using `dirfd` with the one that we use in `Dir::close` for the FD sanity check. Those target evidently all have `dirfd` as we're using it there, and that's a strict subset of the targets that have `Dir` handles, so they should support `fstatat` as well. try-job: *bsd* try-job: *various*
2 parents 12433c3 + 46b2135 commit dc44e7f

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

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

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ cfg_select! {
3939

4040
#[cfg(all(target_os = "linux", target_env = "gnu"))]
4141
use libc::c_char;
42-
#[cfg(any(
43-
all(target_os = "linux", not(target_env = "musl")),
44-
target_os = "android",
45-
target_os = "fuchsia",
46-
target_os = "hurd",
47-
target_os = "illumos",
48-
target_vendor = "apple",
49-
))]
50-
use libc::dirfd;
5142
use libc::{c_int, mode_t};
5243

5344
use crate::ffi::{CStr, OsStr, OsString};
@@ -1023,12 +1014,10 @@ impl Drop for DirStream {
10231014
target_os = "nto",
10241015
target_os = "qnx",
10251016
target_os = "vita",
1026-
target_os = "hurd",
10271017
target_os = "espidf",
10281018
target_os = "horizon",
10291019
target_os = "vxworks",
10301020
target_os = "rtems",
1031-
target_os = "nuttx",
10321021
)))]
10331022
{
10341023
let fd = unsafe { libc::dirfd(self.0) };
@@ -1060,15 +1049,17 @@ impl DirEntry {
10601049
pub fn metadata(&self) -> io::Result<FileAttr> {
10611050
cfg_select! {
10621051
// Use directory handle where possible
1063-
any(
1064-
all(target_os = "linux", not(target_env = "musl")),
1065-
target_os = "android",
1066-
target_os = "fuchsia",
1067-
target_os = "hurd",
1068-
target_os = "illumos",
1069-
target_vendor = "apple",
1070-
) => {
1071-
let fd = cvt(unsafe { dirfd(self.dir.dirp.0) })?;
1052+
not(any(
1053+
target_os = "redox",
1054+
target_os = "nto",
1055+
target_os = "qnx",
1056+
target_os = "vita",
1057+
target_os = "espidf",
1058+
target_os = "horizon",
1059+
target_os = "vxworks",
1060+
target_os = "rtems",
1061+
)) => {
1062+
let fd = cvt(unsafe { libc::dirfd(self.dir.dirp.0) })?;
10721063

10731064
// Make this FD into a directory handle. We don't actually drop it,
10741065
// so having an `OwnedFd` is fine.

0 commit comments

Comments
 (0)