Sfoglia il codice sorgente

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

Dan Helfman 2 anni fa
parent
commit
6975a5b155
3 ha cambiato i file con 28 aggiunte e 9 eliminazioni
  1. 1 0
      NEWS
  2. 11 9
      borgmatic/borg/check.py
  3. 16 0
      tests/unit/borg/test_check.py

+ 1 - 0
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.

+ 11 - 9
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,18 +182,14 @@ 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')
+            logger.warning(
+                'Ignoring check_last option, as "archives" or "data" are not in consistency checks'
+            )
         if prefix:
-            logger.info(
-                'Ignoring consistency prefix option, as "archives" is not in consistency checks'
+            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
 
     if {'repository', 'archives'}.issubset(set(checks)):

+ 16 - 0
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)