Skip to content

Commit a81c374

Browse files
committed
Properly feature gate rustix-based functions
1 parent 677efca commit a81c374

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/dirext.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ use cap_primitives::fs::FileType;
1212
use cap_std::fs::{Dir, File, Metadata};
1313
use cap_tempfile::cap_std;
1414
use cap_tempfile::cap_std::fs::DirEntry;
15+
#[cfg(any(target_os = "android", target_os = "linux"))]
1516
use rustix::path::Arg;
1617
use std::cmp::Ordering;
1718
use std::ffi::OsStr;
1819
use std::io::Result;
1920
use std::io::{self, Write};
2021
use std::ops::Deref;
22+
#[cfg(unix)]
2123
use std::os::fd::OwnedFd;
2224
use std::path::{Path, PathBuf};
2325

@@ -447,6 +449,7 @@ fn subdir_of<'d, 'p>(d: &'d Dir, p: &'p Path) -> io::Result<(DirOwnedOrBorrowed<
447449
Ok((r, name))
448450
}
449451

452+
#[cfg(any(target_os = "android", target_os = "linux"))]
450453
/// A thin wrapper for [`openat2`] but that retries on interruption.
451454
fn openat2_with_retry(
452455
dirfd: impl std::os::fd::AsFd,
@@ -474,6 +477,7 @@ fn openat2_with_retry(
474477
})
475478
}
476479

480+
#[cfg(any(target_os = "android", target_os = "linux"))]
477481
fn is_mountpoint_impl_statx(root: &Dir, path: &Path) -> Result<Option<bool>> {
478482
// https://github.com/systemd/systemd/blob/8fbf0a214e2fe474655b17a4b663122943b55db0/src/basic/mountpoint-util.c#L176
479483
use rustix::fs::StatxAttributes;
@@ -577,6 +581,7 @@ where
577581
debug_assert!(matches!(flow, std::ops::ControlFlow::Continue(())));
578582
// Open the child directory, using the noxdev API if
579583
// we're configured not to cross devices,
584+
#[cfg(any(target_os = "android", target_os = "linux"))]
580585
let d = {
581586
if !config.noxdev {
582587
entry.open_dir()?
@@ -587,6 +592,10 @@ where
587592
continue;
588593
}
589594
};
595+
596+
#[cfg(not(any(target_os = "android", target_os = "linux")))]
597+
let d = entry.open_dir()?;
598+
590599
// Recurse into the target directory
591600
walk_inner(&d, path, callback, config)?;
592601
path.pop();
@@ -784,6 +793,7 @@ impl CapStdExtDirExt for Dir {
784793
.map_err(Into::into)
785794
}
786795

796+
#[cfg(any(target_os = "android", target_os = "linux"))]
787797
fn is_mountpoint(&self, path: impl AsRef<Path>) -> Result<Option<bool>> {
788798
is_mountpoint_impl_statx(self, path.as_ref()).map_err(Into::into)
789799
}

0 commit comments

Comments
 (0)