diff --git a/pristine_zip/delta_to_zipball.py b/pristine_zip/delta_to_zipball.py index 96c7d7f..10ad728 100644 --- a/pristine_zip/delta_to_zipball.py +++ b/pristine_zip/delta_to_zipball.py @@ -1,61 +1,62 @@ # Copyright (C) 2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import os import subprocess import tempfile from . import compress def genzip(checkout_dir: str, delta_path: str, zipball_path: str): with tempfile.TemporaryDirectory(prefix="pristine-zip-genzip") as work_dir: reference_zipball_path = os.path.join(work_dir, "reference.zip") # generate reference zipball compress.compress(checkout_dir, reference_zipball_path) _apply_delta(reference_zipball_path, zipball_path, work_dir, delta_path) def _apply_delta( reference_zipball_path: str, zipball_path: str, work_dir: str, delta_path: str, ): proc = subprocess.run(["tar", "--extract", "-f", delta_path,], cwd=work_dir) proc.check_returncode() with open(os.path.join(work_dir, "type"), "rb") as fd: type_ = fd.read().decode().strip() assert type_ == "zip", ( f"Unknown zipball type {type}. Are you" f"extracting a delta from pristine-tar instead of pristine-zip?" ) with open(os.path.join(work_dir, "reference_md5sum"), "rb") as fd: expected_md5sum = fd.read().decode().strip() proc = subprocess.run(["md5sum", reference_zipball_path], capture_output=True) proc.check_returncode() - actual_md5sum = proc.stdout.decode().strip() + actual_md5sum = proc.stdout.decode().split(" ", 1)[0].strip() if actual_md5sum != expected_md5sum: print( - f"md5sum mismatch between reference zipballs. " + f"md5sum mismatch between reference zipballs " + f"(expected '{expected_md5sum}', got '{actual_md5sum}').\n" f"This is a bug, please report it along with the original zipball " f"and the version number of pristine-zip." ) exit(1) xdelta3_path = os.path.join(work_dir, "delta") assert os.path.isfile(xdelta3_path), "Missing 'delta' file in delta archive." _apply_xdelta3(reference_zipball_path, zipball_path, xdelta3_path) def _apply_xdelta3(reference_zipball_path: str, zipball_path: str, xdelta3_path: str): proc = subprocess.run( ["xdelta3", "-d", "-s", reference_zipball_path, xdelta3_path, zipball_path] ) proc.check_returncode()