Skip to content

Commit

Permalink
uncompress_archive: ignore warnings as those are not errors
Browse files Browse the repository at this point in the history
Fixes: #85.
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
  • Loading branch information
otavio committed Jul 24, 2022
1 parent 869b2e6 commit 368ce58
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## [Unreleased] - ReleaseDate

* Avoid failing uncompressing files in case of ARCHIVE_WARN returns [#85]

[#85]: https://github.com/OSSystems/compress-tools-rs/issues/85

## [0.12.3] - 2022-06-22

* ci: windows: Use pre-installed vcpkg and fix build [#81]
Expand Down
2 changes: 2 additions & 0 deletions scripts/generate-ffi
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ bindgen \
--raw-line "pub const ARCHIVE_EOF: i32 = 1;" \
--raw-line "pub const ARCHIVE_OK: i32 = 0;" \
\
--whitelist-var "ARCHIVE_WARN" \
\
--whitelist-var "ARCHIVE_EXTRACT_TIME" \
--whitelist-var "ARCHIVE_EXTRACT_PERM" \
--whitelist-var "ARCHIVE_EXTRACT_ACL" \
Expand Down
7 changes: 3 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ pub enum Error {
}

pub(crate) fn archive_result(value: i32, archive: *mut ffi::archive) -> Result<()> {
if value != ffi::ARCHIVE_OK {
return Err(Error::from(archive));
match value {
ffi::ARCHIVE_OK | ffi::ARCHIVE_WARN => Ok(()),
_ => Err(Error::from(archive)),
}

Ok(())
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
Expand Down
1 change: 1 addition & 0 deletions src/ffi/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pub(crate) const ARCHIVE_EOF: i32 = 1;
pub(crate) const ARCHIVE_OK: i32 = 0;

pub(crate) const ARCHIVE_WARN: i32 = -20;
pub(crate) const ARCHIVE_EXTRACT_OWNER: u32 = 1;
pub(crate) const ARCHIVE_EXTRACT_PERM: u32 = 2;
pub(crate) const ARCHIVE_EXTRACT_TIME: u32 = 4;
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ where
ffi::archive_write_header(archive_writer, entry);
libarchive_copy_data(archive_reader, archive_writer)?;

if ffi::archive_write_finish_entry(archive_writer) != ffi::ARCHIVE_OK {
return Err(Error::from(archive_writer));
}
archive_result(
ffi::archive_write_finish_entry(archive_writer),
archive_writer,
)?;
}
_ => return Err(Error::from(archive_reader)),
}
Expand Down

0 comments on commit 368ce58

Please sign in to comment.