From 6975a5b1559e400e1a7c262be42b5bfca36b5d5e Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 17 Nov 2022 10:19:48 -0800 Subject: [PATCH] Fix "data" consistency check to support "check_last" and consistency "prefix" options (#611). --- NEWS | 1 + borgmatic/borg/check.py | 22 ++++++++++++---------- tests/unit/borg/test_check.py | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 5dde6d7..c8164cf 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ 1.7.5.dev0 * #604: Fix traceback when a configuration section is present but lacking any options. * #607: Clarify examples in include merging and deep merging documentation. + * #611: Fix "data" consistency check to support "check_last" and consistency "prefix" options. 1.7.4 * #596: Fix special file detection erroring when broken symlinks are encountered. diff --git a/borgmatic/borg/check.py b/borgmatic/borg/check.py index f1c860b..484a415 100644 --- a/borgmatic/borg/check.py +++ b/borgmatic/borg/check.py @@ -166,6 +166,12 @@ def make_check_flags(local_borg_version, checks, check_last=None, prefix=None): "--last" flag. And if a prefix value is given and "archives" is in checks, then include a "--match-archives" flag. ''' + if 'data' in checks: + data_flags = ('--verify-data',) + checks += ('archives',) + else: + data_flags = () + if 'archives' in checks: last_flags = ('--last', str(check_last)) if check_last else () if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version): @@ -176,17 +182,13 @@ def make_check_flags(local_borg_version, checks, check_last=None, prefix=None): last_flags = () match_archives_flags = () if check_last: - logger.info('Ignoring check_last option, as "archives" is not in consistency checks') - if prefix: - logger.info( - 'Ignoring consistency prefix option, as "archives" is not in consistency checks' + logger.warning( + 'Ignoring check_last option, as "archives" or "data" are not in consistency checks' + ) + if prefix: + logger.warning( + 'Ignoring consistency prefix option, as "archives" or "data" are not in consistency checks' ) - - if 'data' in checks: - data_flags = ('--verify-data',) - checks += ('archives',) - else: - data_flags = () common_flags = last_flags + match_archives_flags + data_flags diff --git a/tests/unit/borg/test_check.py b/tests/unit/borg/test_check.py index 29fc4a7..ba82225 100644 --- a/tests/unit/borg/test_check.py +++ b/tests/unit/borg/test_check.py @@ -265,6 +265,14 @@ def test_make_check_flags_with_archives_check_and_last_includes_last_flag(): assert flags == ('--archives-only', '--last', '3') +def test_make_check_flags_with_data_check_and_last_includes_last_flag(): + flexmock(module.feature).should_receive('available').and_return(True) + + flags = module.make_check_flags('1.2.3', ('data',), check_last=3) + + assert flags == ('--archives-only', '--last', '3', '--verify-data') + + def test_make_check_flags_with_repository_check_and_last_omits_last_flag(): flexmock(module.feature).should_receive('available').and_return(True) @@ -289,6 +297,14 @@ def test_make_check_flags_with_archives_check_and_prefix_includes_match_archives assert flags == ('--archives-only', '--match-archives', 'sh:foo-*') +def test_make_check_flags_with_data_check_and_prefix_includes_match_archives_flag(): + flexmock(module.feature).should_receive('available').and_return(True) + + flags = module.make_check_flags('1.2.3', ('data',), prefix='foo-') + + assert flags == ('--archives-only', '--match-archives', 'sh:foo-*', '--verify-data') + + def test_make_check_flags_with_archives_check_and_empty_prefix_omits_match_archives_flag(): flexmock(module.feature).should_receive('available').and_return(True)