diff --git a/Cargo.lock b/Cargo.lock index 2591386ba..4065c8d1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4523,7 +4523,6 @@ dependencies = [ "libc", "md-5", "memchr", - "nix", "num-traits", "os_display", "procfs", diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 5761f5ec4..a4a28de47 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -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 } diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index 8f1c14ea0..31858de71 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -513,60 +513,20 @@ impl From for Box { } } -/// Enables the conversion from [`Result`] to [`UResult`]. +/// Enables the conversion from [`Result`] to [`UResult`]. /// /// # 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 FromIo> for Result { - fn map_err_context(self, context: impl FnOnce() -> String) -> UResult { - self.map_err(|e| { - Box::new(UIoError { - context: Some(context()), - inner: std::io::Error::from_raw_os_error(e as i32), - }) as Box - }) - } -} - -#[cfg(unix)] -impl FromIo> for nix::Error { - fn map_err_context(self, context: impl FnOnce() -> String) -> UResult { - Err(Box::new(UIoError { - context: Some(context()), - inner: std::io::Error::from_raw_os_error(self as i32), - }) as Box) - } -} - -#[cfg(unix)] -impl From 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 for Box { - fn from(f: nix::Error) -> Self { - let u_error: UIoError = f.into(); - Box::new(u_error) as Self - } -} - +/// /// Enables the conversion from [`Result`] to [`UResult`]. #[cfg(unix)] impl FromIo> for Result { @@ -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() diff --git a/tests/uutests/Cargo.toml b/tests/uutests/Cargo.toml index 7cac6ab71..a27bb67ee 100644 --- a/tests/uutests/Cargo.toml +++ b/tests/uutests/Cargo.toml @@ -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]