Skip to content

Commit 7ade5c1

Browse files
committed
touch: replace nix by rustix
1 parent c5cff82 commit 7ade5c1

3 files changed

Lines changed: 19 additions & 27 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/touch/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ uucore = { workspace = true, features = ["libc", "parser"] }
2929
fluent = { workspace = true }
3030

3131
[target.'cfg(unix)'.dependencies]
32-
nix = { workspace = true, features = ["fs"] }
32+
libc = { workspace = true }
33+
rustix = { workspace = true, features = ["fs"] }
3334

3435
[dev-dependencies]
3536
tempfile = { workspace = true }

src/uu/touch/src/touch.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use jiff::fmt::strtime;
1616
use jiff::tz::TimeZone;
1717
use jiff::{Timestamp, ToSpan, Zoned};
1818
#[cfg(unix)]
19-
use nix::libc::O_NONBLOCK;
19+
use libc::O_NONBLOCK;
2020
#[cfg(unix)]
21-
use nix::sys::stat::futimens;
21+
use rustix::fs::Timestamps;
2222
#[cfg(unix)]
23-
use nix::sys::time::TimeSpec;
23+
use rustix::fs::futimens;
2424
use std::borrow::Cow;
2525
use std::ffi::{OsStr, OsString};
2626
#[cfg(unix)]
@@ -617,28 +617,18 @@ fn try_futimens_via_write_fd(path: &Path, atime: FileTime, mtime: FileTime) -> s
617617
.custom_flags(O_NONBLOCK)
618618
.open(path)?;
619619

620-
let atime_sec = atime.unix_seconds();
621-
let atime_nsec = i64::from(atime.nanoseconds());
622-
let mtime_sec = mtime.unix_seconds();
623-
let mtime_nsec = i64::from(mtime.nanoseconds());
624-
625-
#[cfg(target_pointer_width = "32")]
626-
let atime_spec = TimeSpec::new(
627-
atime_sec.try_into().unwrap(),
628-
atime_nsec.try_into().unwrap(),
629-
);
630-
#[cfg(target_pointer_width = "64")]
631-
let atime_spec = TimeSpec::new(atime_sec, atime_nsec);
632-
633-
#[cfg(target_pointer_width = "32")]
634-
let mtime_spec = TimeSpec::new(
635-
mtime_sec.try_into().unwrap(),
636-
mtime_nsec.try_into().unwrap(),
637-
);
638-
#[cfg(target_pointer_width = "64")]
639-
let mtime_spec = TimeSpec::new(mtime_sec, mtime_nsec);
640-
641-
futimens(&file, &atime_spec, &mtime_spec).map_err(Error::from)
620+
let timestamps = Timestamps {
621+
last_access: rustix::fs::Timespec {
622+
tv_sec: atime.unix_seconds(),
623+
tv_nsec: atime.nanoseconds() as _,
624+
},
625+
last_modification: rustix::fs::Timespec {
626+
tv_sec: mtime.unix_seconds(),
627+
tv_nsec: mtime.nanoseconds() as _,
628+
},
629+
};
630+
631+
futimens(&file, &timestamps).map_err(|e| Error::from_raw_os_error(e.raw_os_error()))
642632
}
643633

644634
/// Get metadata of the provided path

0 commit comments

Comments
 (0)