From ce5f1589eac0d4ece52ed65345d34eb409446c18 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 10 Feb 2023 14:01:04 +0100 Subject: [PATCH] recreate: --chunker-params must default to None, fixes #7336 also add a test: recreate without --chunker-params shall not rechunk before the fix, it triggered rechunking if an archive was created with non-default chunker params. but it only should rechunk if borg recreate is invoked with explicitly giving --chunker-params=.... --- src/borg/archiver/recreate_cmd.py | 8 +++--- src/borg/testsuite/archiver/recreate_cmd.py | 27 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/borg/archiver/recreate_cmd.py b/src/borg/archiver/recreate_cmd.py index c4a3d6b3c..fe58d5f77 100644 --- a/src/borg/archiver/recreate_cmd.py +++ b/src/borg/archiver/recreate_cmd.py @@ -219,10 +219,10 @@ class RecreateMixIn: 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, + 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( diff --git a/src/borg/testsuite/archiver/recreate_cmd.py b/src/borg/testsuite/archiver/recreate_cmd.py index 435cafb2b..a9b7a34cc 100644 --- a/src/borg/testsuite/archiver/recreate_cmd.py +++ b/src/borg/testsuite/archiver/recreate_cmd.py @@ -171,6 +171,33 @@ 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(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION) + # first create an archive with non-default chunker params: + self.cmd(f"--repo={self.repository_location}", "create", "test", "input", "--chunker-params", "7,9,8,128") + output = self.cmd( + f"--repo={self.repository_location}", "list", "test", "input/file", "--format", "{num_chunks}" + ) + num_chunks = int(output) + # now recreate the archive and do NOT specify chunker params: + output = self.cmd( + f"--repo={self.repository_location}", + "recreate", + "--debug", + "--exclude", + "filename_never_matches", + "-a", + "test", + ) + assert "Rechunking" not in output # we did not give --chunker-params, so it must not rechunk! + output = self.cmd( + f"--repo={self.repository_location}", "list", "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(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)