[PATCH 3/3] goh1_file: deal with false positives from is_zipfile
"Yann Dirson" <[email protected]>
| Newsgroups | org.openembedded.lists.bitbake-devel |
|---|---|
| Message-ID | <[email protected]> |
This function is known https://github.com/python/cpython/issues/72680 for false-positives. With python 3.13.5 there is one with https://vault.almalinux.org/10.0/CRB/x86_64_v2/os/Packages/jdom2-2.0.6.1-8.el10.noarch.rpm The double "is_zipfile = False" is redundant but likely more clear. Signed-off-by: Yann Dirson <[email protected]> --- lib/bb/utils.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/bb/utils.py b/lib/bb/utils.py index 366836bfc..aeeb3f2ee 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -694,14 +694,19 @@ def goh1_file(filename): import zipfile lines = [] + is_zipfile = False if zipfile.is_zipfile(filename): - with zipfile.ZipFile(filename) as archive: - for fn in sorted(archive.namelist()): - method = hashlib.sha256() - method.update(archive.read(fn)) - hash = method.hexdigest() - lines.append("%s %s\n" % (hash, fn)) - else: + try: + with zipfile.ZipFile(filename) as archive: + for fn in sorted(archive.namelist()): + method = hashlib.sha256() + method.update(archive.read(fn)) + hash = method.hexdigest() + lines.append("%s %s\n" % (hash, fn)) + is_zipfile = True + except zipfile.BadZipFile: + is_zipfile = False + if not is_zipfile: hash = _hasher(hashlib.sha256(), filename) lines.append("%s go.mod\n" % hash) method = hashlib.sha256() -- 2.47.3 -- Yann Dirson | Vates Platform Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech