Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zstd support #836

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autospec/pkg_integrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ def quit_verify():
'.bz2': GPGVerifier,
'.xz': GPGVerifier,
'.zip': GPGVerifier,
'.zst': GPGVerifier,
}


Expand Down
5 changes: 5 additions & 0 deletions autospec/specfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ def write_prep(self):
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"):
Expand Down
18 changes: 18 additions & 0 deletions autospec/tarball.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import zipfile

import download
import zstandard as zstd
from util import do_regex, get_sha1sum, print_fatal, write_out


Expand Down Expand Up @@ -53,6 +54,8 @@ def set_type(self):
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'

Expand Down Expand Up @@ -81,6 +84,16 @@ def set_tar_prefix(self):
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."""

Expand Down Expand Up @@ -128,6 +141,11 @@ def extract_zip(self, extraction_path):
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."""
Expand Down
Loading