From 392be868b856d9f9738f3570c9046c27f9b3d163 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 18 Nov 2024 17:11:02 +0100 Subject: [PATCH] osbuild-mpp: Fix error on python < 3.11 The change in commit ed3386943069e138b346eef75ac64d9874a07810 to use hashlib.file_digest breaks with older python, because it was added in 3.11. This change reverts back to hashing all the data in the case where file_digest doesn't exist. --- tools/osbuild-mpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/osbuild-mpp b/tools/osbuild-mpp index f861ba944..778d41f92 100755 --- a/tools/osbuild-mpp +++ b/tools/osbuild-mpp @@ -1604,17 +1604,22 @@ class ManifestFileV2(ManifestFile): if input_count > 1: raise ValueError(f"Only one of 'path', 'url' or 'text' may be specified for '{uid}'") + checksum = None if path: f, _ = self.find_and_open_file(path, [], mode="rb", encoding=None) with f: data = f.read() - checksum = hashlib.sha256(data).hexdigest() elif url: response = urllib.request.urlopen(url) - h = hashlib.file_digest(response.fp, 'sha256') - checksum = h.hexdigest() + if hasattr(hashlib, "file_digest"): + h = hashlib.file_digest(response.fp, 'sha256') + checksum = h.hexdigest() + else: + data = response.fp.read() else: data = bytes(text, "utf-8") + + if not checksum: checksum = hashlib.sha256(data).hexdigest() digest = "sha256:" + checksum