From f926055e67ad211cfab91b324fcab515f5147700 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 21 Apr 2024 14:55:02 -0700 Subject: [PATCH] Fix a traceback when the "data" consistency check is used (#854). --- NEWS | 1 + borgmatic/borg/check.py | 8 ++++---- tests/unit/borg/test_check.py | 16 ++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index 5459f1c..250c50a 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ 1.8.11.dev0 * #851: Fix lack of file extraction when using "extract --strip-components all" on a path with a leading slash. + * #854: Fix a traceback when the "data" consistency check is used. 1.8.10 * #656 (beta): Add a "spot" consistency check that compares file counts and contents between your diff --git a/borgmatic/borg/check.py b/borgmatic/borg/check.py index 9f3c8ce..a58c60d 100644 --- a/borgmatic/borg/check.py +++ b/borgmatic/borg/check.py @@ -52,8 +52,8 @@ def make_archive_filter_flags(local_borg_version, config, checks, check_argument def make_check_flags(checks, archive_filter_flags): ''' - Given a parsed sequence of checks and a sequence of flags to filter archives, transform the - checks into tuple of command-line check flags. + Given a parsed checks set and a sequence of flags to filter archives, + transform the checks into tuple of command-line check flags. For example, given parsed checks of: @@ -68,13 +68,13 @@ def make_check_flags(checks, archive_filter_flags): ''' if 'data' in checks: data_flags = ('--verify-data',) - checks += ('archives',) + checks.update({'archives'}) else: data_flags = () common_flags = (archive_filter_flags if 'archives' in checks else ()) + data_flags - if {'repository', 'archives'}.issubset(set(checks)): + if {'repository', 'archives'}.issubset(checks): return common_flags return ( diff --git a/tests/unit/borg/test_check.py b/tests/unit/borg/test_check.py index 8549e43..d34b4a2 100644 --- a/tests/unit/borg/test_check.py +++ b/tests/unit/borg/test_check.py @@ -223,25 +223,25 @@ def test_make_archive_filter_flags_with_default_checks_and_prefix_includes_match def test_make_check_flags_with_repository_check_returns_flag(): - flags = module.make_check_flags(('repository',), ()) + flags = module.make_check_flags({'repository'}, ()) assert flags == ('--repository-only',) def test_make_check_flags_with_archives_check_returns_flag(): - flags = module.make_check_flags(('archives',), ()) + flags = module.make_check_flags({'archives'}, ()) assert flags == ('--archives-only',) 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-*')) + 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-*')) + flags = module.make_check_flags({'repository'}, ('--match-archives', 'sh:foo-*')) assert flags == ('--repository-only',) @@ -250,7 +250,7 @@ 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(()) - flags = module.make_check_flags(('data',), ()) + flags = module.make_check_flags({'data'}, ()) assert flags == ( '--archives-only', @@ -262,7 +262,7 @@ def test_make_check_flags_with_extract_omits_extract_flag(): flexmock(module.feature).should_receive('available').and_return(True) flexmock(module.flags).should_receive('make_match_archives_flags').and_return(()) - flags = module.make_check_flags(('extract',), ()) + flags = module.make_check_flags({'extract'}, ()) assert flags == () @@ -272,10 +272,10 @@ def test_make_check_flags_with_repository_and_data_checks_does_not_return_reposi flexmock(module.flags).should_receive('make_match_archives_flags').and_return(()) flags = module.make_check_flags( - ( + { 'repository', 'data', - ), + }, (), )