Skip to content

Commit

Permalink
Merge branch 'main' into freebsd
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode authored Sep 19, 2023
2 parents c711e66 + 4e92198 commit 53d7f2c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
16 changes: 15 additions & 1 deletion cap-primitives/src/rustix/fs/metadata_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions cap-primitives/src/rustix/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
};
Expand Down
2 changes: 1 addition & 1 deletion cap-tempfile/src/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand Down

0 comments on commit 53d7f2c

Please sign in to comment.