Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize source/exclude paths before matching #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion attic/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ def _process(self, archive, cache, excludes, exclude_caches, skip_inodes, path,
self.print_error('%s: %s', path, e)
else:
for filename in sorted(entries):
entry_path = os.path.normpath(os.path.join(path, filename))
self._process(archive, cache, excludes, exclude_caches, skip_inodes,
os.path.join(path, filename), restrict_dev)
entry_path, restrict_dev)
elif stat.S_ISLNK(st.st_mode):
archive.process_symlink(path, st)
elif stat.S_ISFIFO(st.st_mode):
Expand Down
6 changes: 3 additions & 3 deletions attic/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class IncludePattern:
path match as well. A trailing slash makes no difference.
"""
def __init__(self, pattern):
self.pattern = pattern.rstrip(os.path.sep)+os.path.sep
self.pattern = os.path.normpath(pattern).rstrip(os.path.sep)+os.path.sep

def match(self, path):
return (path+os.path.sep).startswith(self.pattern)
Expand All @@ -243,9 +243,9 @@ class ExcludePattern(IncludePattern):
"""
def __init__(self, pattern):
if pattern.endswith(os.path.sep):
self.pattern = pattern+'*'+os.path.sep
self.pattern = os.path.normpath(pattern).rstrip(os.path.sep)+os.path.sep+'*'+os.path.sep
else:
self.pattern = pattern+os.path.sep+'*'
self.pattern = os.path.normpath(pattern)+os.path.sep+'*'
# fnmatch and re.match both cache compiled regular expressions.
# Nevertheless, this is about 10 times faster.
self.regex = re.compile(translate(self.pattern))
Expand Down
19 changes: 19 additions & 0 deletions attic/testsuite/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,25 @@ def test_path_normalization(self):
self.assert_not_in('..', output)
self.assert_in(' input/dir1/dir2/file', output)

def test_exclude_normalization(self):
self.attic('init', self.repository_location)
self.create_regular_file('file1', size=1024 * 80)
self.create_regular_file('file2', size=1024 * 80)
with changedir('input'):
self.attic('create', '--exclude=file1', self.repository_location + '::test1', '.')
with changedir('output'):
self.attic('extract', self.repository_location + '::test1')
self.assert_equal(sorted(os.listdir('output')), ['file2'])
with changedir('input'):
self.attic('create', '--exclude=./file1', self.repository_location + '::test2', '.')
with changedir('output'):
self.attic('extract', self.repository_location + '::test2')
self.assert_equal(sorted(os.listdir('output')), ['file2'])
self.attic('create', '--exclude=input/./file1', self.repository_location + '::test3', 'input')
with changedir('output'):
self.attic('extract', self.repository_location + '::test3')
self.assert_equal(sorted(os.listdir('output/input')), ['file2'])

def test_repeated_files(self):
self.create_regular_file('file1', size=1024 * 80)
self.attic('init', self.repository_location)
Expand Down