From e3425f48beca920f9845dfb31f644c8cd7c42367 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 16 May 2023 10:20:52 -0700 Subject: [PATCH] Instead of taking the first check time found, take the maximum value (#688) --- borgmatic/borg/check.py | 6 +++--- tests/unit/borg/test_check.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/borgmatic/borg/check.py b/borgmatic/borg/check.py index 63acbe26..930c82b6 100644 --- a/borgmatic/borg/check.py +++ b/borgmatic/borg/check.py @@ -299,7 +299,7 @@ def probe_for_check_time(location_config, borg_repository_id, check, archives_ch ~/.borgmatic/checks/1234567890/archives/9876543210 ~/.borgmatic/checks/1234567890/archives/all - ... and returns the modification time of the first file found (if any). The first path + ... and returns the maximum modification time of the files found (if any). The first path represents a more specific archives check time (a check on a subset of archives), and the second is a fallback to the last "all" archives check. @@ -318,8 +318,8 @@ def probe_for_check_time(location_config, borg_repository_id, check, archives_ch ) try: - return next(check_time for check_time in check_times if check_time) - except StopIteration: + return max(check_time for check_time in check_times if check_time) + except ValueError: return None diff --git a/tests/unit/borg/test_check.py b/tests/unit/borg/test_check.py index aad973bd..89db5d20 100644 --- a/tests/unit/borg/test_check.py +++ b/tests/unit/borg/test_check.py @@ -462,13 +462,13 @@ def test_read_check_time_on_missing_file_does_not_raise(): assert module.read_check_time('/path') is None -def test_probe_for_check_time_uses_first_of_multiple_check_times(): +def test_probe_for_check_time_uses_maximum_of_multiple_check_times(): flexmock(module).should_receive('make_check_time_path').and_return( '~/.borgmatic/checks/1234/archives/5678' ).and_return('~/.borgmatic/checks/1234/archives/all') flexmock(module).should_receive('read_check_time').and_return(1).and_return(2) - assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 1 + assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 2 def test_probe_for_check_time_deduplicates_identical_check_time_paths():