Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 18 additions & 2 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,18 @@ impl<R: Read> Archive<R> {
/// ```
pub fn unpack<P: AsRef<Path>>(&mut self, dst: P) -> io::Result<()> {
let me: &mut Archive<dyn Read> = self;
me._unpack(dst.as_ref())
me._unpack(dst.as_ref(), |_| {})
}

/// Same as [`unpack`][Self::unpack], but allows mapping entries during the
/// iteration.
pub fn unpack_mapped<P: AsRef<Path>>(
&mut self,
dst: P,
map_entry: impl Fn(&mut Entry<io::Empty>),
) -> io::Result<()> {
let me: &mut Archive<dyn Read> = self;
me._unpack(dst.as_ref(), map_entry)
}

/// Set the mask of the permission bits when unpacking this entry.
Expand Down Expand Up @@ -226,7 +237,7 @@ impl Archive<dyn Read + '_> {
})
}

fn _unpack(&mut self, dst: &Path) -> io::Result<()> {
fn _unpack(&mut self, dst: &Path, map_entry: impl Fn(&mut Entry<io::Empty>)) -> io::Result<()> {
if dst.symlink_metadata().is_err() {
fs::create_dir_all(dst)
.map_err(|e| TarError::new(format!("failed to create `{}`", dst.display()), e))?;
Expand All @@ -245,6 +256,11 @@ impl Archive<dyn Read + '_> {
let mut directories = Vec::new();
for entry in self._entries(None)? {
let mut file = entry.map_err(|e| TarError::new("failed to iterate over archive", e))?;

// Map the entry if needed (e.g. to map its path).
// In most cases, this will be a no-op.
map_entry(&mut file);

if file.header().entry_type() == crate::EntryType::Directory {
directories.push(file);
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ impl<'a, R: Read> Entry<'a, R> {
self.fields.path_bytes()
}

/// Sets the raw bytes listed for this entry.
///
/// Subsequent calls to [`path_bytes`][Self::path_bytes] will return the
/// provided value.
pub fn set_path_bytes(&mut self, path_bytes: Vec<u8>) {
self.fields.long_pathname = Some(path_bytes);
}

/// Returns the link name for this entry, if any is found.
///
/// This method may fail if the pathname is not valid Unicode and this is
Expand Down