diff mbox series

[RFC] bb/fetch: prefer bsdunzip (from libarchive) when unpacking zip files

Message ID 20261202225534.577768-1-ross.burton@arm.com
State New
Headers show
Series [RFC] bb/fetch: prefer bsdunzip (from libarchive) when unpacking zip files | expand

Commit Message

Ross Burton Dec. 2, 2026, 10:55 p.m. UTC
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 <ross.burton@arm.com>
---
 lib/bb/fetch/__init__.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

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)