Fix "data" consistency check to support "check_last" and consistency "prefix" options (#611).

This commit is contained in:
Dan Helfman 2022-11-17 10:19:48 -08:00
parent b627d00595
commit 6975a5b155
3 changed files with 29 additions and 10 deletions

1
NEWS
View File

@ -1,6 +1,7 @@
1.7.5.dev0 1.7.5.dev0
* #604: Fix traceback when a configuration section is present but lacking any options. * #604: Fix traceback when a configuration section is present but lacking any options.
* #607: Clarify examples in include merging and deep merging documentation. * #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 1.7.4
* #596: Fix special file detection erroring when broken symlinks are encountered. * #596: Fix special file detection erroring when broken symlinks are encountered.

View File

@ -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 "--last" flag. And if a prefix value is given and "archives" is in checks, then include a
"--match-archives" flag. "--match-archives" flag.
''' '''
if 'data' in checks:
data_flags = ('--verify-data',)
checks += ('archives',)
else:
data_flags = ()
if 'archives' in checks: if 'archives' in checks:
last_flags = ('--last', str(check_last)) if check_last else () last_flags = ('--last', str(check_last)) if check_last else ()
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version): 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 = () last_flags = ()
match_archives_flags = () match_archives_flags = ()
if check_last: if check_last:
logger.info('Ignoring check_last option, as "archives" is not in consistency checks') logger.warning(
if prefix: 'Ignoring check_last option, as "archives" or "data" are not in consistency checks'
logger.info( )
'Ignoring consistency prefix option, as "archives" is 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 common_flags = last_flags + match_archives_flags + data_flags

View File

@ -265,6 +265,14 @@ def test_make_check_flags_with_archives_check_and_last_includes_last_flag():
assert flags == ('--archives-only', '--last', '3') 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(): def test_make_check_flags_with_repository_check_and_last_omits_last_flag():
flexmock(module.feature).should_receive('available').and_return(True) 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-*') 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(): def test_make_check_flags_with_archives_check_and_empty_prefix_omits_match_archives_flag():
flexmock(module.feature).should_receive('available').and_return(True) flexmock(module.feature).should_receive('available').and_return(True)