diff --git a/cap-primitives/src/rustix/fs/metadata_ext.rs b/cap-primitives/src/rustix/fs/metadata_ext.rs index fd72ea0a..29813c43 100644 --- a/cap-primitives/src/rustix/fs/metadata_ext.rs +++ b/cap-primitives/src/rustix/fs/metadata_ext.rs @@ -100,6 +100,7 @@ impl MetadataExt { /// Constructs a new instance of `Metadata` from the given `Stat`. #[inline] + #[allow(unused_comparisons)] // NB: rust-lang/rust#115823 requires this here instead of on `st_dev` processing below pub(crate) fn from_rustix(stat: Stat) -> Metadata { Metadata { file_type: ImplFileTypeExt::from_raw_mode(stat.st_mode as RawMode), @@ -164,7 +165,20 @@ impl MetadataExt { created: None, ext: Self { - dev: u64::try_from(stat.st_dev).unwrap(), + // The type of `st_dev` is `dev_t` which is signed on some + // platforms and unsigned on other platforms. A `u64` is enough + // to work for all unsigned platforms, and for signed platforms + // perform a sign extension to `i64` and then view that as an + // unsigned 64-bit number instead. + // + // Note that the `unused_comparisons` is ignored here for + // platforms where it's unsigned since the first branch here + // will never be taken. + dev: if stat.st_dev < 0 { + i64::try_from(stat.st_dev).unwrap() as u64 + } else { + u64::try_from(stat.st_dev).unwrap() + }, ino: stat.st_ino.into(), #[cfg(not(target_os = "wasi"))] mode: u32::from(stat.st_mode), diff --git a/cap-primitives/src/rustix/fs/mod.rs b/cap-primitives/src/rustix/fs/mod.rs index 09155804..29129d30 100644 --- a/cap-primitives/src/rustix/fs/mod.rs +++ b/cap-primitives/src/rustix/fs/mod.rs @@ -134,9 +134,10 @@ fn tty_path() { #[cfg(unix)] use std::os::unix::fs::FileTypeExt; - // On FreeBSD, `ttyname` doesn't seem to work on /dev/std{in,out,err}. + // On FreeBSD, /dev/{tty,stdin,stdout,stderr} are aliases to different real + // devices. let paths: &[&str] = if cfg!(target_os = "freebsd") { - &["/dev/tty"] + &["/dev/ttyv0", "/dev/pts/0"] } else { &["/dev/tty", "/dev/stdin", "/dev/stdout", "/dev/stderr"] }; diff --git a/cap-tempfile/src/tempfile.rs b/cap-tempfile/src/tempfile.rs index 26da4d0b..88da2247 100644 --- a/cap-tempfile/src/tempfile.rs +++ b/cap-tempfile/src/tempfile.rs @@ -270,7 +270,7 @@ mod test { let metadata = tf.as_file().metadata().unwrap(); let mode = metadata.mode(); let mode = Mode::from_bits_truncate(mode); - assert_eq!(0o666 & !umask, mode.bits() & 0o7777); + assert_eq!(0o666 & !umask, mode.bits() & 0o777); } // And that we can write tf.write_all(b"hello world")?;