Skip to content

Commit

Permalink
Fix directory exclusions (#467)
Browse files Browse the repository at this point in the history
Different versions of python append different strings to the pattern
created when turning a glob into a regular expression.  For example,
the pattern:

.snapshot/

on python 2.4, glob.fnmatch.translate() would yield '.snapshot/',
while on python 2.6 and above, we get u'\.snapshot\\/\\Z(?ms)'.

Our test for "is this pattern a directory" was thus failing on python
2.6, testing for 'endswith('/').  Whoops.

This patch tests for both types of pattern endings now.

This fixes #467 and fixes Fedora Infrastructure's sync of EPEL content
into S3 regional mirrors.
  • Loading branch information
mdomsch committed Jan 27, 2015
1 parent 6d86ac2 commit 14fa894
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions S3/FileLists.py
Expand Up @@ -98,15 +98,17 @@ def handle_exclude_include_walk(root, dirs, files):
debug(u"CHECK: %r" % d)
excluded = False
for r in cfg.exclude:
if not r.pattern.endswith(u'/'): continue # we only check for directories here
# python versions end their patterns (from globs) differently, test for both styles.
if not (r.pattern.endswith(u'/') or r.pattern.endswith(u'\\/\\Z(?ms)')): continue # we only check for directory patterns here
if r.search(d):
excluded = True
debug(u"EXCL-MATCH: '%s'" % (cfg.debug_exclude[r]))
break
if excluded:
## No need to check for --include if not excluded
for r in cfg.include:
if not r.pattern.endswith(u'/'): continue # we only check for directories here
# python versions end their patterns (from globs) differently, test for both styles.
if not (r.pattern.endswith(u'/') or r.pattern.endswith(u'\\/\\Z(?ms)')): continue # we only check for directory patterns here
debug(u"INCL-TEST: %s ~ %s" % (d, r.pattern))
if r.search(d):
excluded = False
Expand Down

0 comments on commit 14fa894

Please sign in to comment.