From 33ad183a40bfa74e78d43f19dae93236d97fd118 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Tue, 5 Nov 2019 13:45:04 +0100 Subject: [PATCH] src/pxar/decoder.rs: allow to pass match pattern to restore In order to partially restore the archive starting from the directory provided as parameter. Signed-off-by: Christian Ebner --- src/pxar/decoder.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pxar/decoder.rs b/src/pxar/decoder.rs index 34f59ca1..a319346d 100644 --- a/src/pxar/decoder.rs +++ b/src/pxar/decoder.rs @@ -11,7 +11,8 @@ use failure::*; use libc; use super::format_definition::*; -use super::sequential_decoder::*; +use super::sequential_decoder::SequentialDecoder; +use super::match_pattern::MatchPattern; use proxmox::tools::io::ReadExt; @@ -65,11 +66,13 @@ impl Result<(), Error>> Decoder { self.root_end } - pub fn restore(&mut self, dir: &DirectoryEntry, path: &Path) -> Result<(), Error> { + /// Restore the subarchive starting at `dir` to the provided target `path`. + /// + /// Only restore the content matched by the MatchPattern `pattern`. + /// An empty Vec `pattern` means restore all. + pub fn restore(&mut self, dir: &DirectoryEntry, path: &Path, pattern: &Vec) -> Result<(), Error> { let start = dir.start; - self.seek(SeekFrom::Start(start))?; - // Except for the root dir, `DirectoryEntry` start points to the filename. // But `SequentialDecoder::restore()` expects the entry point to be of // type `PxarEntry`, so lets skip over the filename here if present. @@ -80,7 +83,7 @@ impl Result<(), Error>> Decoder { } let _filename = self.inner.read_filename(header.size)?; } - self.inner.restore(path, &Vec::new())?; + self.inner.restore(path, pattern)?; Ok(()) }