浏览代码

diff: normalize chunker params before comparing them, fixes #7079

borg < 1.2 did not have the chunker name as first element in the tuple,
but it always was buzhash, because there was no other chunker.
Thomas Waldmann 2 年之前
父节点
当前提交
a6207370a9
共有 2 个文件被更改,包括 17 次插入3 次删除
  1. 5 3
      src/borg/archiver.py
  2. 12 0
      src/borg/helpers/misc.py

+ 5 - 3
src/borg/archiver.py

@@ -67,7 +67,7 @@ try:
     from .helpers import ProgressIndicatorPercent
     from .helpers import basic_json_data, json_print
     from .helpers import replace_placeholders
-    from .helpers import ChunkIteratorFileWrapper
+    from .helpers import ChunkIteratorFileWrapper, normalize_chunker_params
     from .helpers import popen_with_error_handling, prepare_subprocess_env, create_filter_process
     from .helpers import dash_open
     from .helpers import umount
@@ -1125,8 +1125,10 @@ class Archiver:
         archive2 = Archive(repository, key, manifest, args.archive2,
                            consider_part_files=args.consider_part_files)
 
-        can_compare_chunk_ids = archive1.metadata.get('chunker_params', False) == archive2.metadata.get(
-            'chunker_params', True) or args.same_chunker_params
+        cp1 = archive1.metadata.get('chunker_params')
+        cp2 = archive2.metadata.get('chunker_params')
+        can_compare_chunk_ids = (args.same_chunker_params or
+            cp1 is not None and cp2 is not None and normalize_chunker_params(cp1) == normalize_chunker_params(cp2))
         if not can_compare_chunk_ids:
             self.print_warning('--chunker-params might be different between archives, diff will be slow.\n'
                                'If you know for certain that they are the same, pass --same-chunker-params '

+ 12 - 0
src/borg/helpers/misc.py

@@ -16,6 +16,7 @@ from .time import to_localtime
 from . import msgpack
 from .. import __version__ as borg_version
 from .. import chunker
+from ..constants import CH_BUZHASH, CH_FIXED
 
 
 def prune_within(archives, hours, kept_because):
@@ -119,6 +120,17 @@ def log_multi(*msgs, level=logging.INFO, logger=logger):
         logger.log(level, line)
 
 
+def normalize_chunker_params(cp):
+    assert isinstance(cp, (list, tuple))
+    if isinstance(cp, list):
+        cp = tuple(cp)
+    if len(cp) == 4 and isinstance(cp[0], int):
+        # this is a borg < 1.2 chunker_params tuple, no chunker algo specified, but we only had buzhash:
+        cp = (CH_BUZHASH, ) + cp
+    assert cp[0] in (CH_BUZHASH, CH_FIXED)
+    return cp
+
+
 class ChunkIteratorFileWrapper:
     """File-like wrapper for chunk iterators"""