diff --git a/autospec/pkg_integrity.py b/autospec/pkg_integrity.py index ed7bf2e..9a0e602 100644 --- a/autospec/pkg_integrity.py +++ b/autospec/pkg_integrity.py @@ -532,6 +532,7 @@ VERIFIER_TYPES = { '.bz2': GPGVerifier, '.xz': GPGVerifier, '.zip': GPGVerifier, + '.zst': GPGVerifier, } diff --git a/autospec/specfiles.py b/autospec/specfiles.py index bb5f072..cf9e6b0 100644 --- a/autospec/specfiles.py +++ b/autospec/specfiles.py @@ -465,6 +465,11 @@ class Specfile(object): extract_cmd = 'unzip -q {}' if archive.endswith('.bz2') and not archive.endswith('.tar.bz2'): extract_cmd = 'bzcat {0} > $(basename "{0}" .bz2)' + if archive.endswith('.zst'): + if archive.endswith('.tar.zst'): + extract_cmd = 'tar -I zstd xf {}' + else: + extract_cmd = 'zstd -dqc {0} > $(basename "{0}" .zst)' self._write_strip('cd %{_builddir}') archive_file = os.path.basename(archive) if self.config.archive_details.get(archive + "prefix"): diff --git a/autospec/tarball.py b/autospec/tarball.py index fe50acc..139b7b6 100644 --- a/autospec/tarball.py +++ b/autospec/tarball.py @@ -24,6 +24,7 @@ import re import sys import tarfile import zipfile +import zstandard as zstd import download from util import do_regex, get_sha1sum, print_fatal, write_out @@ -53,6 +54,8 @@ class Source(): self.type = 'zip' elif self.url.lower().endswith(('.bz2')) and not self.url.lower().endswith(('.tar.bz2')): self.type = 'bz2' + elif self.url.lower().endswith('.zst'): + self.type = 'zst' else: self.type = 'tar' @@ -80,6 +83,16 @@ class Source(): else: print_fatal("Not a valid tar file.") sys.exit(1) + + def set_zst_prefix(self): + """Determine prefix folder name of tar.zst file.""" + with tarfile.open(fileobj=zstd.open(self.path, 'rb'), mode='r|') as content: + lines = content.getnames() + if len(lines) == 0: + print_fatal("Zstd compressed tar file doesn't appear to have any content") + sys.exit(1) + elif len(lines) > 1: + self.prefix = os.path.commonpath(lines) def set_bz2_prefix(self): """No prefix for plain bz2 archives.""" @@ -128,6 +141,10 @@ class Source(): with zipfile.ZipFile(self.path, 'r') as content: content.extractall(path=extraction_path) + def extract_zst(self, extraction_path): + """Extract zst in path.""" + with tarfile.open(fileobj=zstd.open(self.path, 'rb'), mode='r|') as content: + content.extractall(path=extraction_path) def convert_version(ver_str, name): """Remove disallowed characters from the version."""