Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/libarchive/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ pub mod lib {
fn archive_write_new() -> *mut Archive;
fn archive_write_free(a: *mut Archive) -> Result;
fn archive_write_close(a: *mut Archive) -> Result;
fn archive_write_set_bytes_in_last_block(a: *mut Archive, bytes: c_int) -> Result;
fn archive_set_error(a: *mut Archive, err: c_int, fmt: *const c_char, ...);
fn archive_write_set_format_pax_restricted(a: *mut Archive) -> Result;
fn archive_write_add_filter_gzip(a: *mut Archive) -> Result;
fn archive_write_set_filter_option(
Expand All @@ -114,7 +116,6 @@ pub mod lib {
value: *const c_char,
) -> Result;
fn archive_write_set_options(a: *mut Archive, opts: *const c_char) -> Result;
fn archive_write_open_filename(a: *mut Archive, filename: *const c_char) -> Result;
fn archive_write_header(a: *mut Archive, entry: *mut Entry) -> Result;
fn archive_write_data(a: *mut Archive, data: *const c_void, size: usize) -> la_ssize_t;
fn archive_write_finish_entry(a: *mut Archive) -> Result;
Expand Down Expand Up @@ -370,14 +371,17 @@ pub mod lib {
// SAFETY: FFI call with no preconditions.
unsafe { archive_write_new() }
}
pub fn write_free(&self) -> Result {
// SAFETY: self came from archive_write_new(); not used after this.
unsafe { archive_write_free(self.as_mut_ptr()) }
}
pub fn write_close(&self) -> Result {
// SAFETY: self valid.
unsafe { archive_write_close(self.as_mut_ptr()) }
}
/// Granularity the final output block is padded to. libarchive's default
/// pads it to a full block (10 KiB for tar); `archive_write_open_filename`
/// sets 1 (no padding) when writing to a regular file.
Comment thread
robobun marked this conversation as resolved.
Outdated
pub fn write_set_bytes_in_last_block(&self, bytes: c_int) -> Result {
// SAFETY: self valid.
unsafe { archive_write_set_bytes_in_last_block(self.as_mut_ptr(), bytes) }
}
pub fn write_set_format_pax_restricted(&self) -> Result {
// SAFETY: self valid.
unsafe { archive_write_set_format_pax_restricted(self.as_mut_ptr()) }
Expand Down Expand Up @@ -406,10 +410,6 @@ pub mod lib {
// SAFETY: self valid; ZStr guarantees NUL-termination.
unsafe { archive_write_set_options(self.as_mut_ptr(), opts.as_ptr().cast()) }
}
pub fn write_open_filename(&self, filename: &ZStr) -> Result {
// SAFETY: self valid; ZStr guarantees NUL-termination.
unsafe { archive_write_open_filename(self.as_mut_ptr(), filename.as_ptr().cast()) }
}
pub fn write_header(&self, entry: &Entry) -> Result {
// SAFETY: self valid; entry came from Entry::new()/read_next_header().
// `Entry` has interior mutability so `&Entry -> *mut Entry` is sound.
Expand Down Expand Up @@ -831,7 +831,7 @@ pub mod lib {
}

pub unsafe extern "C" fn write_callback(
_a: *mut Archive,
a: *mut Archive,
client_data: *mut c_void,
buff: *const c_void,
length: usize,
Expand All @@ -845,6 +845,11 @@ pub mod lib {
let data = unsafe { core::slice::from_raw_parts(buff.cast::<u8>(), length) };
if this.list.try_reserve(length).is_err() {
this.had_error = true;
// libarchive leaves describing a failed client write to the
// client; this is what `archive_error_string` reports afterwards.
// SAFETY: `a` is the live archive this callback was invoked for;
// the format string has no conversions, so no varargs are read.
unsafe { archive_set_error(a, libc::ENOMEM, c"No memory".as_ptr()) };
return -1;
}
this.list.extend_from_slice(data);
Expand Down
Loading
Loading