1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 17:57:59 +00:00

Add and document path prefix as pattern style

The “extract” command supports extracting all files underneath a given
set of prefix paths. The forthcoming support for extracting files using
a pattern (i.e. only files ending in “.zip”) requires the introduction
of path prefixes as a third pattern style, making it also available for
exclusions.
This commit is contained in:
Michael Hanselmann 2016-01-18 13:09:08 +01:00
parent b6362b5963
commit 848375e2fe
3 changed files with 21 additions and 6 deletions

View file

@ -611,12 +611,12 @@ def do_break_lock(self, args):
helptext = {}
helptext['patterns'] = textwrap.dedent('''
Exclusion patterns support two separate styles, fnmatch and regular
expressions. If followed by a colon (':') the first two characters of
a pattern are used as a style selector. Explicit style selection is necessary
when regular expressions are desired or when the desired fnmatch pattern
starts with two alphanumeric characters followed by a colon (i.e.
`aa:something/*`).
Exclusion patterns support three separate styles, fnmatch, regular
expressions and path prefixes. If followed by a colon (':') the first two
characters of a pattern are used as a style selector. Explicit style
selection is necessary when a non-default style is desired or when the
desired pattern starts with two alphanumeric characters followed by a colon
(i.e. `aa:something/*`).
`Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_ patterns use
a variant of shell pattern syntax, with '*' matching any number of
@ -640,6 +640,10 @@ def do_break_lock(self, args):
documentation for the re module
<https://docs.python.org/3/library/re.html>`_.
Prefix path patterns can be selected with the prefix `pp:`. This pattern
style is useful to match whole sub-directories. The pattern `pp:/data/bar`
matches `/data/bar` and everything therein.
Exclusions can be passed via the command line option `--exclude`. When used
from within a shell the patterns should be quoted to protect them from
expansion.

View file

@ -412,6 +412,7 @@ def _match(self, path):
_PATTERN_STYLES = set([
FnmatchPattern,
PathPrefixPattern,
RegexPattern,
])

View file

@ -324,6 +324,10 @@ def test_invalid_unicode_pattern(pattern):
["/more/data"]),
([r" re:^\s "], ["/data/something00.txt", "/more/data", "/home", "/whitespace/end\t"]),
([r" re:\s$ "], ["/data/something00.txt", "/more/data", "/home", " #/wsfoobar", "\tstart/whitespace"]),
(["pp:./"], None),
(["pp:/"], [" #/wsfoobar", "\tstart/whitespace"]),
(["pp:aaabbb"], None),
(["pp:/data", "pp: #/", "pp:\tstart", "pp:/whitespace"], ["/more/data", "/home"]),
])
def test_patterns_from_file(tmpdir, lines, expected):
files = [
@ -364,6 +368,12 @@ def evaluate(filename):
("re:.*", RegexPattern),
("re:^/something/", RegexPattern),
("re:re:^/something/", RegexPattern),
# Path prefix
("pp:", PathPrefixPattern),
("pp:/", PathPrefixPattern),
("pp:/data/", PathPrefixPattern),
("pp:pp:/data/", PathPrefixPattern),
])
def test_parse_pattern(pattern, cls):
assert isinstance(parse_pattern(pattern), cls)