Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/uu/touch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
40 changes: 15 additions & 25 deletions src/uu/touch/src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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, &timestamps).map_err(|e| Error::from_raw_os_error(e.raw_os_error()))
}

/// Get metadata of the provided path
Expand Down
Loading