diff --git a/Cargo.lock b/Cargo.lock index cffb0d9265a..83cc2c0e941 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4303,8 +4303,9 @@ dependencies = [ "filetime", "fluent", "jiff", - "nix", + "libc", "parse_datetime", + "rustix", "tempfile", "thiserror 2.0.18", "uucore", diff --git a/src/uu/touch/Cargo.toml b/src/uu/touch/Cargo.toml index cbcda5ae4a2..4bfff3d5df1 100644 --- a/src/uu/touch/Cargo.toml +++ b/src/uu/touch/Cargo.toml @@ -29,7 +29,8 @@ uucore = { workspace = true, features = ["libc", "parser"] } fluent = { workspace = true } [target.'cfg(unix)'.dependencies] -nix = { workspace = true, features = ["fs"] } +libc = { workspace = true } +rustix = { workspace = true, features = ["fs"] } [dev-dependencies] tempfile = { workspace = true } diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index beeb738a241..bcb688ee7b3 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -16,11 +16,11 @@ use jiff::fmt::strtime; use jiff::tz::TimeZone; use jiff::{Timestamp, ToSpan, Zoned}; #[cfg(unix)] -use nix::libc::O_NONBLOCK; +use libc::O_NONBLOCK; #[cfg(unix)] -use nix::sys::stat::futimens; +use rustix::fs::Timestamps; #[cfg(unix)] -use nix::sys::time::TimeSpec; +use rustix::fs::futimens; use std::borrow::Cow; use std::ffi::{OsStr, OsString}; #[cfg(unix)] @@ -617,28 +617,18 @@ fn try_futimens_via_write_fd(path: &Path, atime: FileTime, mtime: FileTime) -> s .custom_flags(O_NONBLOCK) .open(path)?; - let atime_sec = atime.unix_seconds(); - let atime_nsec = i64::from(atime.nanoseconds()); - let mtime_sec = mtime.unix_seconds(); - let mtime_nsec = i64::from(mtime.nanoseconds()); - - #[cfg(target_pointer_width = "32")] - let atime_spec = TimeSpec::new( - atime_sec.try_into().unwrap(), - atime_nsec.try_into().unwrap(), - ); - #[cfg(target_pointer_width = "64")] - let atime_spec = TimeSpec::new(atime_sec, atime_nsec); - - #[cfg(target_pointer_width = "32")] - let mtime_spec = TimeSpec::new( - mtime_sec.try_into().unwrap(), - mtime_nsec.try_into().unwrap(), - ); - #[cfg(target_pointer_width = "64")] - let mtime_spec = TimeSpec::new(mtime_sec, mtime_nsec); - - futimens(&file, &atime_spec, &mtime_spec).map_err(Error::from) + let timestamps = Timestamps { + last_access: rustix::fs::Timespec { + tv_sec: atime.unix_seconds(), + tv_nsec: atime.nanoseconds() as _, + }, + last_modification: rustix::fs::Timespec { + tv_sec: mtime.unix_seconds(), + tv_nsec: mtime.nanoseconds() as _, + }, + }; + + futimens(&file, ×tamps).map_err(|e| Error::from_raw_os_error(e.raw_os_error())) } /// Get metadata of the provided path