refactor: remove nix from uucore and date, complete source migration

- Remove nix dependency from uucore Cargo.toml
- Remove nix error conversion impls from error.rs, replace with rustix
- Migrate date's clock_settime/clock_getres from nix to rustix::time
- Replace nix dependency with rustix in date's Cargo.toml
- Update test nix features for test utilities that still need it

The nix crate is now completely removed from all source code (src/).
It remains only as a dev-dependency for test code.
This commit is contained in:
Sylvestre Ledru
2026-03-28 13:12:39 +01:00
parent 2d0e1f3a77
commit a2b5380e27
4 changed files with 27 additions and 62 deletions
Generated
-1
View File
@@ -4523,7 +4523,6 @@ dependencies = [
"libc",
"md-5",
"memchr",
"nix",
"num-traits",
"os_display",
"procfs",
+7 -8
View File
@@ -93,16 +93,15 @@ unic-langid = { workspace = true }
thiserror = { workspace = true }
[target.'cfg(unix)'.dependencies]
nix = { workspace = true, features = [
"dir",
libc = { workspace = true }
rustix = { workspace = true, features = [
"pipe",
"process",
"fs",
"poll",
"signal",
"uio",
"user",
"zerocopy",
"event",
"termios",
"time",
] }
rustix = { workspace = true, features = ["pipe", "process", "fs", "event", "termios", "time"] }
walkdir = { workspace = true, optional = true }
xattr = { workspace = true, optional = true }
+12 -52
View File
@@ -513,60 +513,20 @@ impl From<std::io::Error> for Box<dyn UError> {
}
}
/// Enables the conversion from [`Result<T, nix::Error>`] to [`UResult<T>`].
/// Enables the conversion from [`Result<T, rustix::io::Errno>`] to [`UResult<T>`].
///
/// # Examples
///
/// ```
/// use uucore::error::FromIo;
/// use nix::errno::Errno;
///
/// let nix_err = Err::<(), nix::Error>(Errno::EACCES);
/// let uio_result = nix_err.map_err_context(|| String::from("fix me please!"));
/// let io_err = Err::<(), std::io::Error>(std::io::ErrorKind::PermissionDenied.into());
/// let uio_result = io_err.map_err_context(|| String::from("fix me please!"));
///
/// // prints "fix me please!: Permission denied"
/// println!("{}", uio_result.unwrap_err());
/// ```
#[cfg(unix)]
impl<T> FromIo<UResult<T>> for Result<T, nix::Error> {
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
self.map_err(|e| {
Box::new(UIoError {
context: Some(context()),
inner: std::io::Error::from_raw_os_error(e as i32),
}) as Box<dyn UError>
})
}
}
#[cfg(unix)]
impl<T> FromIo<UResult<T>> for nix::Error {
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
Err(Box::new(UIoError {
context: Some(context()),
inner: std::io::Error::from_raw_os_error(self as i32),
}) as Box<dyn UError>)
}
}
#[cfg(unix)]
impl From<nix::Error> for UIoError {
fn from(f: nix::Error) -> Self {
Self {
context: None,
inner: std::io::Error::from_raw_os_error(f as i32),
}
}
}
#[cfg(unix)]
impl From<nix::Error> for Box<dyn UError> {
fn from(f: nix::Error) -> Self {
let u_error: UIoError = f.into();
Box::new(u_error) as Self
}
}
///
/// Enables the conversion from [`Result<T, rustix::io::Errno>`] to [`UResult<T>`].
#[cfg(unix)]
impl<T> FromIo<UResult<T>> for Result<T, rustix::io::Errno> {
@@ -821,22 +781,22 @@ impl Display for ClapErrorWrapper {
mod tests {
#[test]
#[cfg(unix)]
fn test_nix_error_conversion() {
fn test_rustix_errno_conversion() {
use super::{FromIo, UIoError};
use nix::errno::Errno;
use rustix::io::Errno;
use std::io::ErrorKind;
for (nix_error, expected_error_kind) in [
(Errno::EACCES, ErrorKind::PermissionDenied),
(Errno::ENOENT, ErrorKind::NotFound),
(Errno::EEXIST, ErrorKind::AlreadyExists),
for (errno, expected_error_kind) in [
(Errno::ACCESS, ErrorKind::PermissionDenied),
(Errno::NOENT, ErrorKind::NotFound),
(Errno::EXIST, ErrorKind::AlreadyExists),
] {
let error = UIoError::from(nix_error);
let error = UIoError::from(errno);
assert_eq!(expected_error_kind, error.inner.kind());
}
assert_eq!(
"test: Permission denied",
Err::<(), nix::Error>(Errno::EACCES)
Err::<(), Errno>(Errno::ACCESS)
.map_err_context(|| String::from("test"))
.unwrap_err()
.to_string()
+8 -1
View File
@@ -39,7 +39,14 @@ uucore = { workspace = true, features = [
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
[target.'cfg(unix)'.dependencies]
nix = { workspace = true, features = ["process", "signal", "term", "user"] }
nix = { workspace = true, features = [
"fs",
"process",
"signal",
"socket",
"term",
"user",
] }
rlimit = { workspace = true }
[target.'cfg(all(unix, not(any(target_os = "macos", target_os = "openbsd"))))'.dependencies]