mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-19 14:02:55 +00:00
do not crash for empty archives list in borg rlist date based matching (#7544)
fix ValueError for empty archives list, add a test Signed-off-by: Chirag Aggarwal <thechiragaggarwal@gmail.com>
This commit is contained in:
parent
ed2bc8a8e0
commit
eeefa55428
2 changed files with 14 additions and 1 deletions
|
@ -39,6 +39,9 @@ def get_first_and_last_archive_ts(archives_list):
|
|||
timestamps = [x.ts for x in archives_list]
|
||||
return min(timestamps), max(timestamps)
|
||||
|
||||
if not archives:
|
||||
return archives
|
||||
|
||||
now = archive_ts_now()
|
||||
earliest_ts, latest_ts = get_first_and_last_archive_ts(archives)
|
||||
|
||||
|
@ -46,6 +49,9 @@ def get_first_and_last_archive_ts(archives_list):
|
|||
from_ts = calculate_relative_offset(newer, now, earlier=True) if newer is not None else earliest_ts
|
||||
archives = [x for x in archives if from_ts <= x.ts <= until_ts]
|
||||
|
||||
if not archives:
|
||||
return archives
|
||||
|
||||
earliest_ts, latest_ts = get_first_and_last_archive_ts(archives)
|
||||
if oldest:
|
||||
until_ts = calculate_relative_offset(oldest, earliest_ts, earlier=False)
|
||||
|
@ -136,7 +142,7 @@ def list(
|
|||
regex = re.compile(regex + match_end)
|
||||
archives = [x for x in archives if regex.match(x.name) is not None]
|
||||
|
||||
if any([oldest, newest, older, newer]) and len(archives) > 0:
|
||||
if any([oldest, newest, older, newer]):
|
||||
archives = filter_archives_by_date(archives, oldest=oldest, newest=newest, newer=newer, older=older)
|
||||
if not consider_checkpoints:
|
||||
archives = [x for x in archives if ".checkpoint" not in x.name]
|
||||
|
|
|
@ -92,6 +92,13 @@ def test_date_matching(self):
|
|||
self.assert_in("archive2", output)
|
||||
self.assert_not_in("archive3", output)
|
||||
|
||||
# check for output when timespan older than earliest archive is given. Issue #1711
|
||||
output = self.cmd(
|
||||
f"--repo={self.repository_location}", "check", "-v", "--archives-only", "--older=9999m", exit_code=0
|
||||
)
|
||||
for archive in ("archive1", "archive2", "archive3"):
|
||||
self.assert_not_in(archive, output)
|
||||
|
||||
def test_missing_file_chunk(self):
|
||||
archive, repository = self.open_archive("archive1")
|
||||
with repository:
|
||||
|
|
Loading…
Reference in a new issue