From 1784ca59104ec462d1921303040ab0463204022c Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 30 May 2023 23:19:33 -0700 Subject: [PATCH] Fix "check" action error when repository and archive checks are configured but the archive check gets skipped due to the configured frequency (#704). --- NEWS | 2 ++ borgmatic/borg/check.py | 2 +- borgmatic/commands/borgmatic.py | 2 +- tests/unit/borg/test_check.py | 8 +++++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index b4a92ea..da8a3d6 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ or monitoring), so not even errors are shown. * #688: Tweak archive check probing logic to use the newest timestamp found when multiple exist. * #659: Add Borg 2 date-based matching flags to various actions for archive selection. + * #704: Fix "check" action error when repository and archive checks are configured but the archive + check gets skipped due to the configured frequency. * #706: Fix "--archive latest" on "list" and "info" actions only working on the first of multiple configured repositories. diff --git a/borgmatic/borg/check.py b/borgmatic/borg/check.py index 930c82b..0c417ac 100644 --- a/borgmatic/borg/check.py +++ b/borgmatic/borg/check.py @@ -226,7 +226,7 @@ def make_check_flags(checks, archive_filter_flags): else: data_flags = () - common_flags = archive_filter_flags + data_flags + common_flags = (archive_filter_flags if 'archives' in checks else ()) + data_flags if {'repository', 'archives'}.issubset(set(checks)): return common_flags diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 597868f..535c048 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -36,7 +36,7 @@ from borgmatic.borg import version as borg_version from borgmatic.commands.arguments import parse_arguments from borgmatic.config import checks, collect, convert, validate from borgmatic.hooks import command, dispatch, monitor -from borgmatic.logger import add_custom_log_levels, configure_logging, should_do_markup, DISABLED +from borgmatic.logger import DISABLED, add_custom_log_levels, configure_logging, should_do_markup from borgmatic.signals import configure_signals from borgmatic.verbosity import verbosity_to_log_level diff --git a/tests/unit/borg/test_check.py b/tests/unit/borg/test_check.py index 89db5d2..a1044ba 100644 --- a/tests/unit/borg/test_check.py +++ b/tests/unit/borg/test_check.py @@ -356,12 +356,18 @@ def test_make_check_flags_with_archives_check_returns_flag(): assert flags == ('--archives-only',) -def test_make_check_flags_with_archive_filtler_flags_includes_those_flags(): +def test_make_check_flags_with_archives_check_and_archive_filter_flags_includes_those_flags(): flags = module.make_check_flags(('archives',), ('--match-archives', 'sh:foo-*')) assert flags == ('--archives-only', '--match-archives', 'sh:foo-*') +def test_make_check_flags_without_archives_check_and_with_archive_filter_flags_includes_those_flags(): + flags = module.make_check_flags(('repository',), ('--match-archives', 'sh:foo-*')) + + assert flags == ('--repository-only',) + + def test_make_check_flags_with_data_check_returns_flag_and_implies_archives(): flexmock(module.feature).should_receive('available').and_return(True) flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())