瀏覽代碼

Merge pull request #7337 from ThomasWaldmann/fix-recreate-rechunkify-1.2

recreate without --chunker-params shall not rechunk (1.2)
TW 2 年之前
父節點
當前提交
e41466dbb3
共有 2 個文件被更改,包括 21 次插入4 次删除
  1. 4 4
      src/borg/archiver.py
  2. 17 0
      src/borg/testsuite/archiver.py

+ 4 - 4
src/borg/archiver.py

@@ -4652,10 +4652,10 @@ class Archiver:
                                         'If no MODE is given, `if-different` will be used. '
                                         'Not passing --recompress is equivalent to "--recompress never".')
         archive_group.add_argument('--chunker-params', metavar='PARAMS', dest='chunker_params', action=Highlander,
-                                   type=ChunkerParams, default=CHUNKER_PARAMS,
-                                   help='specify the chunker parameters (ALGO, CHUNK_MIN_EXP, CHUNK_MAX_EXP, '
-                                        'HASH_MASK_BITS, HASH_WINDOW_SIZE) or `default` to use the current defaults. '
-                                        'default: %s,%d,%d,%d,%d' % CHUNKER_PARAMS)
+                                   type=ChunkerParams, default=None,
+                                   help='rechunk using given chunker parameters (ALGO, CHUNK_MIN_EXP, CHUNK_MAX_EXP, '
+                                        'HASH_MASK_BITS, HASH_WINDOW_SIZE) or `default` to use the chunker defaults. '
+                                        'default: do not rechunk')
 
         subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='',
                                type=location_validator(),

+ 17 - 0
src/borg/testsuite/archiver.py

@@ -3080,6 +3080,23 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         num_chunks = int(output)
         assert num_chunks == 2
 
+    def test_recreate_no_rechunkify(self):
+        with open(os.path.join(self.input_path, 'file'), 'wb') as fd:
+            fd.write(b'a' * 8192)
+        self.cmd('init', '--encryption=repokey', self.repository_location)
+        # first create an archive with non-default chunker params:
+        self.cmd('create', '--chunker-params', '7,9,8,128', self.repository_location + '::test', 'input')
+        output = self.cmd('list', self.repository_location + '::test', 'input/file',
+                          '--format', '{num_chunks}')
+        num_chunks = int(output)
+        # now recreate the archive and do NOT specify chunker params:
+        output = self.cmd('recreate', '--debug', '--exclude', 'filename_never_matches', self.repository_location + '::test')
+        assert 'Rechunking' not in output  # we did not give --chunker-params, so it must not rechunk!
+        output = self.cmd('list', self.repository_location + '::test', 'input/file',
+                          '--format', '{num_chunks}')
+        num_chunks_after_recreate = int(output)
+        assert num_chunks == num_chunks_after_recreate
+
     def test_recreate_recompress(self):
         self.create_regular_file('compressible', size=10000)
         self.cmd('init', '--encryption=repokey', self.repository_location)