diff --git a/libarchive/src/error.rs b/libarchive/src/error.rs index 48ca302..737d747 100644 --- a/libarchive/src/error.rs +++ b/libarchive/src/error.rs @@ -19,6 +19,7 @@ pub enum ArchiveError { Consumed, HeaderPosition, Sys(ErrCode, String), + IO(io::Error), } impl error::Error for ArchiveError {} @@ -31,6 +32,7 @@ impl fmt::Display for ArchiveError { ArchiveError::Sys(ref code, ref msg) => { write!(fmt, "{} (libarchive err_code={})", msg, code) } + ArchiveError::IO(ref err) => write!(fmt, "{}", err), } } } @@ -52,6 +54,15 @@ impl<'a> From<&'a dyn archive::Handle> for Result<()> { impl From for io::Error { fn from(err: ArchiveError) -> Self { - io::Error::new(io::ErrorKind::Other, format!("{}", err)) + match err { + ArchiveError::IO(io_err) => io_err, + _ => io::Error::new(io::ErrorKind::Other, format!("{}", err)), + } + } +} + +impl From for ArchiveError { + fn from(err: io::Error) -> Self { + ArchiveError::IO(err) } } diff --git a/libarchive/src/write/file.rs b/libarchive/src/write/file.rs index c0559e1..2bdbd62 100644 --- a/libarchive/src/write/file.rs +++ b/libarchive/src/write/file.rs @@ -35,7 +35,7 @@ impl FileWriter { &mut self, entry: &mut WriteEntry, path: P, - ) -> io::Result<()> { + ) -> crate::Result<()> { unsafe { match ffi::archive_write_header(self.handle_mut(), entry.entry_mut()) { ffi::ARCHIVE_OK => (), @@ -62,7 +62,7 @@ impl FileWriter { }, Err(err) => match err.kind() { io::ErrorKind::Interrupted => (), - _ => return Err(err), + _ => return Err(err.into()), }, }; }