Instead of taking the first check time found, take the maximum value (#688)

This commit is contained in:
Dan Helfman 2023-05-16 10:20:52 -07:00
parent 79b094d035
commit e3425f48be
2 changed files with 5 additions and 5 deletions

View File

@ -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

View File

@ -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():