mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-22 06:01:54 +00:00
Merge pull request #6025 from amikula/issue_6015
Handle case of calling prune_split when there are no archives, #6015
This commit is contained in:
commit
450ab38e42
2 changed files with 16 additions and 1 deletions
|
@ -49,6 +49,8 @@ def prune_split(archives, rule, n, kept_because=None):
|
|||
kept_because = {}
|
||||
if n == 0:
|
||||
return keep
|
||||
|
||||
a = None
|
||||
for a in sorted(archives, key=attrgetter('ts'), reverse=True):
|
||||
period = to_localtime(a.ts).strftime(pattern)
|
||||
if period != last:
|
||||
|
@ -59,7 +61,7 @@ def prune_split(archives, rule, n, kept_because=None):
|
|||
if len(keep) == n:
|
||||
break
|
||||
# Keep oldest archive if we didn't reach the target retention count
|
||||
if len(keep) < n and a.id not in kept_because:
|
||||
if a is not None and len(keep) < n and a.id not in kept_because:
|
||||
keep.append(a)
|
||||
kept_because[a.id] = (rule+"[oldest]", len(keep))
|
||||
return keep
|
||||
|
|
|
@ -439,6 +439,19 @@ def subset(lst, ids):
|
|||
assert kept_because[4][0] == "yearly"
|
||||
|
||||
|
||||
def test_prune_split_no_archives():
|
||||
def subset(lst, ids):
|
||||
return {i for i in lst if i.id in ids}
|
||||
|
||||
archives = []
|
||||
|
||||
kept_because = {}
|
||||
keep = prune_split(archives, "yearly", 3, kept_because)
|
||||
|
||||
assert keep == []
|
||||
assert kept_because == {}
|
||||
|
||||
|
||||
class IntervalTestCase(BaseTestCase):
|
||||
def test_interval(self):
|
||||
self.assert_equal(interval('1H'), 1)
|
||||
|
|
Loading…
Reference in a new issue