1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-22 14:11:27 +00:00

Simplify IncludePattern and add a few more tests to PatternTestCase.

This commit is contained in:
Dan Christensen 2014-02-07 16:27:18 -05:00
parent db9632532c
commit 8cc74be62e
2 changed files with 5 additions and 3 deletions

View file

@ -165,11 +165,10 @@ class IncludePattern:
path match as well. A trailing slash makes no difference. path match as well. A trailing slash makes no difference.
""" """
def __init__(self, pattern): def __init__(self, pattern):
self.pattern = pattern.rstrip(os.path.sep) self.pattern = pattern.rstrip(os.path.sep)+os.path.sep
def match(self, path): def match(self, path):
return (path == self.pattern return (path+os.path.sep).startswith(self.pattern)
or path.startswith(self.pattern+os.path.sep))
def __repr__(self): def __repr__(self):
return '%s(%s)' % (type(self), self.pattern) return '%s(%s)' % (type(self), self.pattern)

View file

@ -61,6 +61,9 @@ def evaluate(self, paths, excludes):
return [path for path in self.files if not exclude_path(path, patterns)] return [path for path in self.files if not exclude_path(path, patterns)]
def test(self): def test(self):
self.assert_equal(self.evaluate(['/'], []), self.files)
self.assert_equal(self.evaluate([], []), self.files)
self.assert_equal(self.evaluate(['/'], ['/h']), self.files)
self.assert_equal(self.evaluate(['/'], ['/home']), self.assert_equal(self.evaluate(['/'], ['/home']),
['/etc/passwd', '/etc/hosts', '/var/log/messages', '/var/log/dmesg']) ['/etc/passwd', '/etc/hosts', '/var/log/messages', '/var/log/dmesg'])
self.assert_equal(self.evaluate(['/'], ['/home/']), self.assert_equal(self.evaluate(['/'], ['/home/']),