diff --git a/build.rs b/build.rs index 02dc64fa..33a6803e 100644 --- a/build.rs +++ b/build.rs @@ -34,7 +34,7 @@ fn use_feature(feature: &str) { /// Test whether the rustc at `var("RUSTC")` supports the given feature. fn has_feature(feature: &str) -> bool { - can_compile(&format!( + can_compile(format!( "#![allow(stable_features)]\n#![feature({})]", feature )) @@ -48,8 +48,8 @@ fn can_compile>(test: T) -> bool { let rustc = var("RUSTC").unwrap(); let target = var("TARGET").unwrap(); - // Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string, - // as documented [here]. + // Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string, as + // documented [here]. // [here]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads let wrapper = var("RUSTC_WRAPPER") .ok() diff --git a/cap-primitives/Cargo.toml b/cap-primitives/Cargo.toml index 7e0bc9eb..5e387d2a 100644 --- a/cap-primitives/Cargo.toml +++ b/cap-primitives/Cargo.toml @@ -25,7 +25,7 @@ io-lifetimes = { version = "2.0.0", default-features = false } cap-tempfile = { path = "../cap-tempfile" } [target.'cfg(not(windows))'.dependencies] -rustix = { version = "0.38.0", features = ["fs", "process", "procfs", "termios", "time"] } +rustix = { version = "0.38.32", features = ["fs", "process", "procfs", "termios", "time"] } [target.'cfg(windows)'.dependencies] winx = "0.36.0" diff --git a/cap-primitives/src/rustix/fs/metadata_ext.rs b/cap-primitives/src/rustix/fs/metadata_ext.rs index 0cd9de03..5330637d 100644 --- a/cap-primitives/src/rustix/fs/metadata_ext.rs +++ b/cap-primitives/src/rustix/fs/metadata_ext.rs @@ -102,6 +102,9 @@ impl ImplMetadataExt { #[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 { + #[cfg(not(target_os = "wasi"))] + use rustix::fs::StatExt; + Metadata { file_type: ImplFileTypeExt::from_raw_mode(stat.st_mode as RawMode), len: u64::try_from(stat.st_size).unwrap(), @@ -112,12 +115,12 @@ impl ImplMetadataExt { #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] modified: system_time_from_rustix( - stat.st_mtime.try_into().unwrap(), + stat.mtime().try_into().unwrap(), stat.st_mtime_nsec as _, ), #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] accessed: system_time_from_rustix( - stat.st_atime.try_into().unwrap(), + stat.atime().try_into().unwrap(), stat.st_atime_nsec as _, ), @@ -191,19 +194,19 @@ impl ImplMetadataExt { rdev: u64::try_from(stat.st_rdev).unwrap(), size: u64::try_from(stat.st_size).unwrap(), #[cfg(not(target_os = "wasi"))] - atime: i64::try_from(stat.st_atime).unwrap(), + atime: i64::try_from(stat.atime()).unwrap(), #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] atime_nsec: stat.st_atime_nsec as _, #[cfg(target_os = "netbsd")] atime_nsec: stat.st_atimensec as _, #[cfg(not(target_os = "wasi"))] - mtime: i64::try_from(stat.st_mtime).unwrap(), + mtime: i64::try_from(stat.mtime()).unwrap(), #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] mtime_nsec: stat.st_mtime_nsec as _, #[cfg(target_os = "netbsd")] mtime_nsec: stat.st_mtimensec as _, #[cfg(not(target_os = "wasi"))] - ctime: i64::try_from(stat.st_ctime).unwrap(), + ctime: i64::try_from(stat.ctime()).unwrap(), #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] ctime_nsec: stat.st_ctime_nsec as _, #[cfg(target_os = "netbsd")] diff --git a/cap-tempfile/src/tempfile.rs b/cap-tempfile/src/tempfile.rs index 6dbd2a2c..2b5d2f05 100644 --- a/cap-tempfile/src/tempfile.rs +++ b/cap-tempfile/src/tempfile.rs @@ -215,7 +215,6 @@ impl<'d> Drop for TempFile<'d> { #[cfg(test)] mod test { use super::*; - use std::io; /// On Unix, calling `umask()` actually *mutates* the process global state. /// This uses Linux `/proc` to read the current value. diff --git a/cap-time-ext/src/lib.rs b/cap-time-ext/src/lib.rs index 99a3de81..255bb0c7 100644 --- a/cap-time-ext/src/lib.rs +++ b/cap-time-ext/src/lib.rs @@ -15,4 +15,4 @@ mod timezone; pub use monotonic_clock::MonotonicClockExt; pub use system_clock::SystemClockExt; -pub use timezone::Timezone; +pub use timezone::{Timezone, TimezoneError}; diff --git a/cap-time-ext/src/timezone.rs b/cap-time-ext/src/timezone.rs index 4cc440e8..7002452d 100644 --- a/cap-time-ext/src/timezone.rs +++ b/cap-time-ext/src/timezone.rs @@ -4,9 +4,18 @@ use iana_time_zone::get_timezone; /// A reference to a timezone resource. pub struct Timezone(()); +/// An error type returned by `Timezone::timezone_name`. #[derive(Debug)] pub struct TimezoneError(String); +impl std::error::Error for TimezoneError {} + +impl std::fmt::Display for TimezoneError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + impl Timezone { /// Constructs a new instance of `Self`. /// diff --git a/tests/sys_common/symlink_junction.rs b/tests/sys_common/symlink_junction.rs index 3bfe2ec3..6a7f0b20 100644 --- a/tests/sys_common/symlink_junction.rs +++ b/tests/sys_common/symlink_junction.rs @@ -54,6 +54,7 @@ pub fn symlink_junction_utf8, Q: AsRef>( /// /// This is enough for almost all of the buffers we're likely to work with in /// the Windows APIs we use. +#[cfg(windows)] #[repr(C, align(8))] #[derive(Copy, Clone)] struct Align8(pub T);