fix #2873: if --pattern is used, default to not extracting

The extraction algorithm has a state (bool) indicating
whether we're currently in a positive or negative match
which has always been initialized to true at the beginning,
but when the user provides a `--pattern` argument we need to
start out with a negative match.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-07-30 09:29:20 +02:00
parent d53fbe2474
commit d44185c4a1
3 changed files with 9 additions and 1 deletions

View File

@ -1375,6 +1375,7 @@ async fn restore(param: Value) -> Result<Value, Error> {
pxar::decoder::Decoder::from_std(reader)?, pxar::decoder::Decoder::from_std(reader)?,
Path::new(target), Path::new(target),
&[], &[],
true,
proxmox_backup::pxar::Flags::DEFAULT, proxmox_backup::pxar::Flags::DEFAULT,
allow_existing_dirs, allow_existing_dirs,
|path| { |path| {

View File

@ -24,11 +24,13 @@ fn extract_archive_from_reader<R: std::io::Read>(
allow_existing_dirs: bool, allow_existing_dirs: bool,
verbose: bool, verbose: bool,
match_list: &[MatchEntry], match_list: &[MatchEntry],
extract_match_default: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
proxmox_backup::pxar::extract_archive( proxmox_backup::pxar::extract_archive(
pxar::decoder::Decoder::from_std(reader)?, pxar::decoder::Decoder::from_std(reader)?,
Path::new(target), Path::new(target),
&match_list, &match_list,
extract_match_default,
feature_flags, feature_flags,
allow_existing_dirs, allow_existing_dirs,
|path| { |path| {
@ -162,6 +164,8 @@ fn extract_archive(
); );
} }
let extract_match_default = match_list.is_empty();
if archive == "-" { if archive == "-" {
let stdin = std::io::stdin(); let stdin = std::io::stdin();
let mut reader = stdin.lock(); let mut reader = stdin.lock();
@ -172,6 +176,7 @@ fn extract_archive(
allow_existing_dirs, allow_existing_dirs,
verbose, verbose,
&match_list, &match_list,
extract_match_default,
)?; )?;
} else { } else {
if verbose { if verbose {
@ -186,6 +191,7 @@ fn extract_archive(
allow_existing_dirs, allow_existing_dirs,
verbose, verbose,
&match_list, &match_list,
extract_match_default,
)?; )?;
} }

View File

@ -27,6 +27,7 @@ pub fn extract_archive<T, F>(
mut decoder: pxar::decoder::Decoder<T>, mut decoder: pxar::decoder::Decoder<T>,
destination: &Path, destination: &Path,
match_list: &[MatchEntry], match_list: &[MatchEntry],
extract_match_default: bool,
feature_flags: Flags, feature_flags: Flags,
allow_existing_dirs: bool, allow_existing_dirs: bool,
mut callback: F, mut callback: F,
@ -69,7 +70,7 @@ where
); );
let mut match_stack = Vec::new(); let mut match_stack = Vec::new();
let mut current_match = true; let mut current_match = extract_match_default;
while let Some(entry) = decoder.next() { while let Some(entry) = decoder.next() {
use pxar::EntryKind; use pxar::EntryKind;