From: Wolfgang Bumiller Date: Thu, 15 Oct 2020 10:26:45 +0000 (+0200) Subject: pxar: anchor pxarexcludes starting with a slash X-Git-Tag: v0.9.2~116 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=8d841f81ee012e31f75bc47b09e5fdc9f99c3e0e;p=proxmox-backup.git pxar: anchor pxarexcludes starting with a slash Given the .pxarexclude file foo /bar The following happens: exclude: /foo exclude: /bar exclude: /subdir/foo include: /subdir/bar since the `/bar` line is an absolute path Signed-off-by: Wolfgang Bumiller --- diff --git a/src/pxar/create.rs b/src/pxar/create.rs index 046f7455..74c49050 100644 --- a/src/pxar/create.rs +++ b/src/pxar/create.rs @@ -12,7 +12,7 @@ use nix::errno::Errno; use nix::fcntl::OFlag; use nix::sys::stat::{FileStat, Mode}; -use pathpatterns::{MatchEntry, MatchList, MatchType, PatternFlag}; +use pathpatterns::{MatchEntry, MatchFlag, MatchList, MatchType, PatternFlag}; use pxar::Metadata; use pxar::encoder::LinkOffset; @@ -325,25 +325,31 @@ impl<'a, 'b> Archiver<'a, 'b> { } let mut buf; - let (line, mode) = if line[0] == b'/' { + let (line, mode, anchored) = if line[0] == b'/' { buf = Vec::with_capacity(path_bytes.len() + 1 + line.len()); buf.extend(path_bytes); buf.extend(line); - (&buf[..], MatchType::Exclude) + (&buf[..], MatchType::Exclude, true) } else if line.starts_with(b"!/") { // inverted case with absolute path buf = Vec::with_capacity(path_bytes.len() + line.len()); buf.extend(path_bytes); buf.extend(&line[1..]); // without the '!' - (&buf[..], MatchType::Include) + (&buf[..], MatchType::Include, true) } else if line.starts_with(b"!") { - (&line[1..], MatchType::Include) + (&line[1..], MatchType::Include, false) } else { - (line, MatchType::Exclude) + (line, MatchType::Exclude, false) }; match MatchEntry::parse_pattern(line, PatternFlag::PATH_NAME, mode) { - Ok(pattern) => self.patterns.push(pattern), + Ok(pattern) => { + if anchored { + self.patterns.push(pattern.add_flags(MatchFlag::ANCHORED)); + } else { + self.patterns.push(pattern); + } + } Err(err) => { let _ = writeln!(self.errors, "bad pattern in {:?}: {}", self.path, err); } @@ -1000,7 +1006,7 @@ fn process_acl( /// Since we are generating an *exclude* list, we need to invert this, so includes get a `'!'` /// prefix. fn generate_pxar_excludes_cli(patterns: &[MatchEntry]) -> Vec { - use pathpatterns::{MatchFlag, MatchPattern}; + use pathpatterns::MatchPattern; let mut content = Vec::new();