From 8f57f29ca84dbfdb99a822fdfbba43b361577a81 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 23 Apr 2020 11:40:53 +0200 Subject: [PATCH] proxmox: add SysError::is_errno_raw to work around missing errno values in nix 0.16 Signed-off-by: Wolfgang Bumiller --- proxmox/src/sys/error.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/proxmox/src/sys/error.rs b/proxmox/src/sys/error.rs index 7adfed78..65bc7183 100644 --- a/proxmox/src/sys/error.rs +++ b/proxmox/src/sys/error.rs @@ -55,7 +55,13 @@ pub fn io_err_other(e: E) -> io::Error { /// ``` pub trait SysError { /// Check if this error is a specific error returned from a system call. - fn is_errno(&self, value: Errno) -> bool; + fn is_errno(&self, value: Errno) -> bool { + self.is_errno_raw(value as i32) + } + + /// Check if this error is a specific error returned from a system call, without involving the + /// `nix::errno::Errno` type as it is incomplete. + fn is_errno_raw(&self, value: i32) -> bool; /// Convert this error into a `std::io::Error`. This must use the correct `std::io::ErrorKind`, /// so that for example `ErrorKind::WouldBlock` means that the previous system call failed with @@ -83,8 +89,8 @@ pub trait SysError { impl SysError for io::Error { #[inline] - fn is_errno(&self, value: Errno) -> bool { - self.raw_os_error() == Some(value as i32) + fn is_errno_raw(&self, value: i32) -> bool { + self.raw_os_error() == Some(value) } #[inline] @@ -99,6 +105,14 @@ impl SysError for nix::Error { *self == Error::Sys(value) } + #[inline] + fn is_errno_raw(&self, value: i32) -> bool { + match *self { + Error::Sys(errno) => value == errno as i32, + _ => false, + } + } + #[inline] fn into_io_error(self) -> io::Error { match self {