From d7a545a5dfc7491d4b7b7abbd5ab371799dc06e8 Mon Sep 17 00:00:00 2001 From: jetchirag Date: Thu, 27 Apr 2023 22:53:36 +0530 Subject: [PATCH 1/3] Added a check on timestamp to prevent ValueError --- src/borg/manifest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/borg/manifest.py b/src/borg/manifest.py index 4eb9b1e3bf..3ff55c2500 100644 --- a/src/borg/manifest.py +++ b/src/borg/manifest.py @@ -37,6 +37,8 @@ class MandatoryFeatureUnsupported(Error): def filter_archives_by_date(archives, older=None, newer=None, oldest=None, newest=None): def get_first_and_last_archive_ts(archives_list): timestamps = [x.ts for x in archives_list] + if not timestamps: + return None, None return min(timestamps), max(timestamps) now = archive_ts_now() From 82b4caec833408b911158b31d7b82f7ae43b10bd Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 19 May 2023 18:24:09 -0400 Subject: [PATCH 2/3] Added test for the bug and fix Signed-off-by: Chirag Aggarwal --- src/borg/manifest.py | 10 +++++++--- src/borg/testsuite/archiver/check_cmd.py | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/borg/manifest.py b/src/borg/manifest.py index 3ff55c2500..c6409f4b7f 100644 --- a/src/borg/manifest.py +++ b/src/borg/manifest.py @@ -37,10 +37,11 @@ class MandatoryFeatureUnsupported(Error): def filter_archives_by_date(archives, older=None, newer=None, oldest=None, newest=None): def get_first_and_last_archive_ts(archives_list): timestamps = [x.ts for x in archives_list] - if not timestamps: - return None, None 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) @@ -48,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) @@ -138,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] diff --git a/src/borg/testsuite/archiver/check_cmd.py b/src/borg/testsuite/archiver/check_cmd.py index 023a983d67..0e93c77f1c 100644 --- a/src/borg/testsuite/archiver/check_cmd.py +++ b/src/borg/testsuite/archiver/check_cmd.py @@ -92,6 +92,11 @@ 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 + ) + def test_missing_file_chunk(self): archive, repository = self.open_archive("archive1") with repository: From d35436c255e3e571bf80088ab2e59c4f3dc51b0b Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 19 May 2023 20:40:08 -0400 Subject: [PATCH 3/3] test that it gives the expected result (all archives "not in" the output) Signed-off-by: Chirag Aggarwal --- src/borg/testsuite/archiver/check_cmd.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/borg/testsuite/archiver/check_cmd.py b/src/borg/testsuite/archiver/check_cmd.py index 0e93c77f1c..9669ee7ac5 100644 --- a/src/borg/testsuite/archiver/check_cmd.py +++ b/src/borg/testsuite/archiver/check_cmd.py @@ -96,6 +96,8 @@ def test_date_matching(self): 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")