prune: fix checkpoints processing with --glob-archives

before the fix, the archives_checkpoints list could not always contain
checkpoints as the glob regex matched the end of the name, so there
could be no additional ".checkpoint" after the match.
This commit is contained in:
Thomas Waldmann 2017-07-03 01:23:37 +02:00
parent d33b853f66
commit ac98fe3fbe
2 changed files with 9 additions and 6 deletions

View file

@ -1476,8 +1476,11 @@ class Archiver:
return self.exit_code
if args.prefix:
args.glob_archives = args.prefix + '*'
archives_checkpoints = manifest.archives.list(glob=args.glob_archives, sort_by=['ts'], reverse=True)
is_checkpoint = re.compile(r'\.checkpoint(\.\d+)?$').search
checkpoint_re = r'\.checkpoint(\.\d+)?'
archives_checkpoints = manifest.archives.list(glob=args.glob_archives,
match_end=r'(%s)?\Z' % checkpoint_re,
sort_by=['ts'], reverse=True)
is_checkpoint = re.compile(r'(%s)\Z' % checkpoint_re).search
checkpoints = [arch for arch in archives_checkpoints if is_checkpoint(arch.name)]
# keep the latest checkpoint, if there is no later non-checkpoint archive
if archives_checkpoints and checkpoints and archives_checkpoints[0] is checkpoints[0]:

View file

@ -219,18 +219,18 @@ class Archives(abc.MutableMapping):
name = safe_encode(name)
del self._archives[name]
def list(self, *, glob=None, sort_by=(), first=None, last=None, reverse=False):
def list(self, *, glob=None, match_end=r'\Z', sort_by=(), first=None, last=None, reverse=False):
"""
Return list of ArchiveInfo instances according to the parameters.
First match *glob*, then *sort_by*. Apply *first* and *last* filters,
and possibly *reverse* the list.
First match *glob* (considering *match_end*), then *sort_by*.
Apply *first* and *last* filters, and then possibly *reverse* the list.
*sort_by* is a list of sort keys applied in reverse order.
"""
if isinstance(sort_by, (str, bytes)):
raise TypeError('sort_by must be a sequence of str')
regex = re.compile(shellpattern.translate(glob or '*'))
regex = re.compile(shellpattern.translate(glob or '*', match_end=match_end))
archives = [x for x in self.values() if regex.match(x.name) is not None]
for sortkey in reversed(sort_by):
archives.sort(key=attrgetter(sortkey))