From 085a8ef7c7665d1ff3437f2c41201dec8d180d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 13 Jul 2017 14:10:02 +0200 Subject: [PATCH] checksum: Checksum each image only once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no point in reading the same image multiple times. This happens for at least source ISOs. Signed-off-by: Lubomír Sedlář --- pungi/phases/image_checksum.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pungi/phases/image_checksum.py b/pungi/phases/image_checksum.py index fcdba9bd..77394b96 100644 --- a/pungi/phases/image_checksum.py +++ b/pungi/phases/image_checksum.py @@ -73,7 +73,8 @@ class ImageChecksumPhase(PhaseBase): make_checksums(topdir, self.compose.im, self.checksums, self.one_file, self._get_base_filename) -def _compute_checksums(results, variant, arch, path, images, checksum_types, base_checksum_name, one_file): +def _compute_checksums(results, cache, variant, arch, path, images, + checksum_types, base_checksum_name, one_file): for image in images: filename = os.path.basename(image.path) full_path = os.path.join(path, filename) @@ -82,7 +83,12 @@ def _compute_checksums(results, variant, arch, path, images, checksum_types, bas filesize = image.size or get_file_size(full_path) - digests = shortcuts.compute_file_checksums(full_path, checksum_types) + if full_path not in cache: + # Source ISO is listed under each binary architecture. There's no + # point in checksumming it twice, so we can just remember the + # digest from first run.. + cache[full_path] = shortcuts.compute_file_checksums(full_path, checksum_types) + digests = cache[full_path] for checksum, digest in digests.iteritems(): # Update metadata with the checksum image.add_checksum(None, checksum, digest) @@ -101,9 +107,10 @@ def _compute_checksums(results, variant, arch, path, images, checksum_types, bas def make_checksums(topdir, im, checksum_types, one_file, base_checksum_name_gen): results = defaultdict(set) + cache = {} for (variant, arch, path), images in get_images(topdir, im).iteritems(): base_checksum_name = base_checksum_name_gen(variant, arch) - _compute_checksums(results, variant, arch, path, images, + _compute_checksums(results, cache, variant, arch, path, images, checksum_types, base_checksum_name, one_file) for file in results: