mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
fix: conditionally enable nix
error conversions
This commit is contained in:
parent
c19c19e4db
commit
81ea9521ce
2 changed files with 12 additions and 5 deletions
|
@ -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";
|
||||
|
|
|
@ -522,6 +522,7 @@ impl From<std::io::Error> for Box<dyn UError> {
|
|||
/// // prints "fix me please!: Permission denied"
|
||||
/// println!("{}", uio_result.unwrap_err());
|
||||
/// ```
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
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| {
|
||||
|
@ -533,6 +534,7 @@ impl<T> FromIo<UResult<T>> for Result<T, nix::Error> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
impl<T> FromIo<UResult<T>> for nix::Error {
|
||||
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
|
||||
Err(Box::new(UIoError {
|
||||
|
@ -542,6 +544,7 @@ impl<T> FromIo<UResult<T>> for nix::Error {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
impl From<nix::Error> for UIoError {
|
||||
fn from(f: nix::Error) -> Self {
|
||||
Self {
|
||||
|
@ -551,6 +554,7 @@ impl From<nix::Error> for UIoError {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
impl From<nix::Error> for Box<dyn UError> {
|
||||
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),
|
||||
|
|
Loading…
Reference in a new issue