summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/util/tar.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/util/tar.rs b/src/util/tar.rs
index 41df63e..5e64bb2 100644
--- a/src/util/tar.rs
+++ b/src/util/tar.rs
@@ -34,7 +34,10 @@ pub fn pack<W: Write, P: AsRef<Path>, E: AsRef<Path>, I: Iterator<Item = E>>(
ar.into_inner()
}
-pub fn unpack<R: Read, P: AsRef<Path>>(archive: R, dest: P) -> Result<()> {
+pub fn unpack_filter<R: Read, P: AsRef<Path>, F>(archive: R, dest: P, filter: F) -> Result<()>
+where
+ for<'a> F: Fn(&tar::Entry<'a, R>) -> bool,
+{
let dest_path = dest.as_ref();
DirBuilder::new().recursive(true).create(dest_path)?;
@@ -46,6 +49,9 @@ pub fn unpack<R: Read, P: AsRef<Path>>(archive: R, dest: P) -> Result<()> {
for entry_r in ar.entries()? {
let mut entry = entry_r?;
+ if !filter(&entry) {
+ continue;
+ }
if entry.unpack_in(dest_path)? {
let header = entry.header();
let uid = header.uid()? as libc::uid_t;
@@ -61,3 +67,7 @@ pub fn unpack<R: Read, P: AsRef<Path>>(archive: R, dest: P) -> Result<()> {
Ok(())
}
+
+pub fn unpack<R: Read, P: AsRef<Path>>(archive: R, dest: P) -> Result<()> {
+ unpack_filter(archive, dest, |_| true)
+}