diff mbox series

[01/14] backports: Add support deb with zstd compression

Message ID 20211011222227.1189850-2-hauke@hauke-m.de (mailing list archive)
State New, archived
Headers show
Series backports: Remove support for kernel < 4.4 | expand

Commit Message

Hauke Mehrtens Oct. 11, 2021, 10:22 p.m. UTC
The recent mainline .deb files from Ubuntu are using zstd compression.
The default python tarfile API does not support zstd compression. Use
the zpystd package from pip to decompress the stream and then use
tarfile to unpack it.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 devel/backports-update-manager | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/devel/backports-update-manager b/devel/backports-update-manager
index 4d63de8c..9177be76 100755
--- a/devel/backports-update-manager
+++ b/devel/backports-update-manager
@@ -5,6 +5,7 @@  from urllib.request import urlopen
 from urllib.parse import urljoin
 import tarfile, tempfile
 import fileinput, subprocess
+from pyzstd import ZstdFile
 source_dir = os.path.abspath(os.path.dirname(__file__))
 sys.path.append(source_dir + '/../')
 from lib import bpar as ar
@@ -541,8 +542,14 @@  class backport_kernel_updater:
                 sys.stdout.write("%s - extracting new %s ...\n" % (kver.get('ver'), target))
                 data, dpath = tempfile.mkstemp(prefix=tmp_prefix)
                 ar.print_data(target, data)
-                tar = tarfile.open(name=dpath, mode='r')
-                tar.extractall(path=tmpdir_path, members=bk_tar_members(tar))
+                try:
+                   tar = tarfile.open(name=dpath, mode='r')
+                   tar.extractall(path=tmpdir_path, members=bk_tar_members(tar))
+                except (tarfile.ReadError):
+                   zstd_file = ZstdFile(dpath)
+                   tar = tarfile.open(fileobj=zstd_file, mode='r')
+                   tar.extractall(path=tmpdir_path, members=bk_tar_members(tar))
+                   zstd_file.close()
                 os.unlink(dpath)
 
                 self.sanitize_and_install_kernel_dirs(tmpdir_path)