feat(libarchive): wrap io errors as well
parent
6eb95aabbf
commit
00a0a62ab0
|
@ -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<ArchiveError> 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<io::Error> for ArchiveError {
|
||||
fn from(err: io::Error) -> Self {
|
||||
ArchiveError::IO(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue