Skip to content

Commit

Permalink
Support zstd-compressed repositories
Browse files Browse the repository at this point in the history
A repository may now be compressed using zstd. Extend support
to allow for this, in addition to continuing to support
gzip-encoded repositories.
  • Loading branch information
nicois committed Jul 2, 2024
1 parent 1b38cfd commit da00c1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies = [
"python-dateutil>=2.8.1,<3",
"botocore>=1.23.50,<2",
"lxml>=4.6.5,<5",
"zstd>=1.5.5.1",
]

[project.optional-dependencies]
Expand Down
1 change: 1 addition & 0 deletions rpm_s3_mirror.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Requires: python3-requests
Requires: python3-dateutil
Requires: python3-botocore
Requires: python3-lxml
Requires: python3-zstd
Requires: systemd
Requires: zchunk

Expand Down
12 changes: 10 additions & 2 deletions rpm_s3_mirror/repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2020 Aiven, Helsinki, Finland. https://aiven.io/
import dataclasses
import lzma
import zstd
import re
import subprocess
from abc import abstractmethod
Expand Down Expand Up @@ -404,8 +405,15 @@ def _extract_package_list(self, primary: RepodataSection) -> PackageList:
with self._req(self.session.get, path=primary.location, stream=True) as request:
with TemporaryDirectory(prefix="/var/tmp/") as temp_dir:
local_path = download_repodata_section(primary, request, temp_dir)
with gzip.open(local_path) as f:
return PackageList(base_url=self.base_url, packages_xml=f.read())

try:
with open(local_path, "rb") as f:
packages_xml = zstd.decompress(f.read())
except zstd.Error:
with gzip.open(local_path) as f:
packages_xml = f.read()

return PackageList(base_url=self.base_url, packages_xml=packages_xml)

def parse_repomd(self, xml: Element) -> Dict[str, RepodataSection]:
sections = {}
Expand Down

0 comments on commit da00c1c

Please sign in to comment.