From patchwork Wed Dec 2 22:55:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 107046 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.1186.1796252138125055356 for ; Wed, 02 Dec 2026 14:55:38 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="dkim: body hash did not verify" header.i=@arm.com header.s=foss header.b=WOgAJDvS; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ross.burton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C6B9F1516 for ; Wed, 2 Dec 2026 14:55:34 -0800 (PST) Received: from cesw-amp-gbt-1s-m12830-04.lab.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 365433F86F for ; Wed, 2 Dec 2026 14:55:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796252137; bh=lye5kRLlqrxJXXuAh+iiOFDMu91NvZRTMwsZOtTysSA=; h=From:To:Subject:Date:From; b=WOgAJDvS46Ypeul2U/t9gmIRWdMNZ5H4uxMT38Ir3/xcGbbcWSFufs9O6kM1dwOJG orRsct5sdGygZye8237kOFyU7ihEYqTD8yB+IVKzKKnUvNXI1lZe4PgglLHbu9Kp4b pvLgtAvvFAyDRcwyY7JhB3KWN704x3UhAMzuPlcM= From: Ross Burton To: bitbake-devel@lists.openembedded.org Subject: [RFC PATCH] bb/fetch: prefer bsdunzip (from libarchive) when unpacking zip files Date: Wed, 2 Dec 2026 22:55:34 +0000 Message-ID: <20261202225534.577768-1-ross.burton@arm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-ARM-No-Footer: NoDisclaimer List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Wed, 02 Dec 2026 22:55:47 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/bitbake-devel/message/20525 The classic unzip was last released in 2009[1] and obviously unmaintained. There are a number of alternatives we could use: - libarchive's bsdunzip (designed to be a drop-in replacement for unzip) - 7z (also supports zip files) - Python's zipfile module (API has an entry point to unpack) All of these are actually a performance improvement over unzip: Benchmark 1: unzip github.com.u-root.u-root@v0.14.0.zip Time (mean ± σ): 650.6 ms ± 2.5 ms Benchmark 1: bsdunzip github.com.u-root.u-root@v0.14.0.zip Time (mean ± σ): 337.0 ms ± 2.0 ms Benchmark 1: 7z x github.com.u-root.u-root@v0.14.0.zip Time (mean ± σ): 446.0 ms ± 9.7 ms Benchmark 1: python3 -mzipfile --extract github.com.u-root.u-root@v0.14.0.zip . Time (mean ± σ): 465.3 ms ± 2.1 ms However, the zip unpacking code exposes a 'dos' parameter which unpacks text files with native line endings instead of the original line endings, which is occasionally used when dealing with zip files from Windows environments. We probably want to keep this functionality, so that rules out 7z. We could implement a zipfile-based unpacker directly in the fetcher code that supports this functionality, but the easiest approach is to prefer bsdunzip if it's present. This lets users of bitbake choose between either sticking with unzip, or using libarchive instead. [1] Info-Zip unzip 6.0, April 2009, https://infozip.sourceforge.net/UnZip.html Signed-off-by: Ross Burton --- lib/bb/fetch/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bb/fetch/__init__.py b/lib/bb/fetch/__init__.py index f67955a674..6f55971900 100644 --- a/lib/bb/fetch/__init__.py +++ b/lib/bb/fetch/__init__.py @@ -22,6 +22,7 @@ import dataclasses import subprocess import pickle import shlex +import shutil import weakref import bb.utils import bb.checksum @@ -1597,7 +1598,12 @@ class FetchMethod(object): except ValueError as exc: bb.fatal("Invalid value for 'dos' parameter for %s: %s" % (file, urldata.parm.get('dos'))) - cmd = ['unzip', '-q', '-o'] + # Prefer libarchive's bsdunzip, fall back to unzip + if shutil.which("bsdunzip"): + cmd = ["bsdunzip"] + else: + cmd = ["unzip"] + cmd += ['-q', '-o'] if dos: cmd.append('-a') cmd.append(file)