osbuild-mpp: Fix error on python < 3.11
The change in commit ed33869430 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.
This commit is contained in:
parent
af7b7db66f
commit
9c3e5107aa
1 changed files with 8 additions and 3 deletions
|
|
@ -1604,17 +1604,22 @@ class ManifestFileV2(ManifestFile):
|
||||||
if input_count > 1:
|
if input_count > 1:
|
||||||
raise ValueError(f"Only one of 'path', 'url' or 'text' may be specified for '{uid}'")
|
raise ValueError(f"Only one of 'path', 'url' or 'text' may be specified for '{uid}'")
|
||||||
|
|
||||||
|
checksum = None
|
||||||
if path:
|
if path:
|
||||||
f, _ = self.find_and_open_file(path, [], mode="rb", encoding=None)
|
f, _ = self.find_and_open_file(path, [], mode="rb", encoding=None)
|
||||||
with f:
|
with f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
checksum = hashlib.sha256(data).hexdigest()
|
|
||||||
elif url:
|
elif url:
|
||||||
response = urllib.request.urlopen(url)
|
response = urllib.request.urlopen(url)
|
||||||
h = hashlib.file_digest(response.fp, 'sha256')
|
if hasattr(hashlib, "file_digest"):
|
||||||
checksum = h.hexdigest()
|
h = hashlib.file_digest(response.fp, 'sha256')
|
||||||
|
checksum = h.hexdigest()
|
||||||
|
else:
|
||||||
|
data = response.fp.read()
|
||||||
else:
|
else:
|
||||||
data = bytes(text, "utf-8")
|
data = bytes(text, "utf-8")
|
||||||
|
|
||||||
|
if not checksum:
|
||||||
checksum = hashlib.sha256(data).hexdigest()
|
checksum = hashlib.sha256(data).hexdigest()
|
||||||
|
|
||||||
digest = "sha256:" + checksum
|
digest = "sha256:" + checksum
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue