diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index a0139dcdf..08ba6b1d4 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -16,7 +16,9 @@ use nix::fcntl::{open, OFlag}; use nix::sys::stat::Mode; use std::path::Path; use uucore::display::Quotable; -use uucore::error::{FromIo, UResult, USimpleError}; +#[cfg(any(target_os = "linux", target_os = "android"))] +use uucore::error::FromIo; +use uucore::error::{UResult, USimpleError}; use uucore::format_usage; static ABOUT: &str = "Synchronize cached writes to persistent storage"; diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index de53f2ef3..5f6f21b77 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -522,6 +522,7 @@ impl From for Box { /// // prints "fix me please!: Permission denied" /// println!("{}", uio_result.unwrap_err()); /// ``` +#[cfg(any(target_os = "linux", target_os = "android"))] impl FromIo> for Result { fn map_err_context(self, context: impl FnOnce() -> String) -> UResult { self.map_err(|e| { @@ -533,6 +534,7 @@ impl FromIo> for Result { } } +#[cfg(any(target_os = "linux", target_os = "android"))] impl FromIo> for nix::Error { fn map_err_context(self, context: impl FnOnce() -> String) -> UResult { Err(Box::new(UIoError { @@ -542,6 +544,7 @@ impl FromIo> for nix::Error { } } +#[cfg(any(target_os = "linux", target_os = "android"))] impl From for UIoError { fn from(f: nix::Error) -> Self { Self { @@ -551,6 +554,7 @@ impl From for UIoError { } } +#[cfg(any(target_os = "linux", target_os = "android"))] impl From for Box { fn from(f: nix::Error) -> Self { let u_error: UIoError = f.into(); @@ -746,12 +750,13 @@ impl Display for ClapErrorWrapper { #[cfg(test)] mod tests { - use super::*; - use nix::errno::Errno; - use std::io::ErrorKind; - #[test] + #[cfg(any(target_os = "linux", target_os = "android"))] fn test_nix_error_conversion() { + use super::{FromIo, UIoError}; + use nix::errno::Errno; + use std::io::ErrorKind; + for (nix_error, expected_error_kind) in [ (Errno::EACCES, ErrorKind::PermissionDenied), (Errno::ENOENT, ErrorKind::NotFound),