Skip to content

Commit

Permalink
osbuild-mpp: Fix error on python < 3.11
Browse files Browse the repository at this point in the history
The change in commit ed33869 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.
  • Loading branch information
alexlarsson committed Nov 18, 2024
1 parent a8e8ebd commit bdce170
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tools/osbuild-mpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,17 +1604,20 @@ 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 = bytes(text, "utf-8")

if not checksum:
checksum = hashlib.sha256(data).hexdigest()

digest = "sha256:" + checksum
Expand Down

0 comments on commit bdce170

Please sign in to comment.