Skip to content

Commit 7045e1b

Browse files
authored
Merge pull request #708 from furlongm/zstd-support
add support for zstd compression in deb and rpm repos
2 parents cc14aea + 856f41f commit 7045e1b

File tree

6 files changed

+28
-2
lines changed

6 files changed

+28
-2
lines changed

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Depends: ${misc:Depends}, python3 (>= 3.11), python3-django (>= 4.2),
2020
python3-requests, python3-colorama, python3-magic, python3-humanize,
2121
python3-yaml, libapache2-mod-wsgi-py3, apache2, sqlite3,
2222
celery, python3-celery, python3-django-celery-beat, redis-server,
23-
python3-redis, python3-git, python3-django-taggit
23+
python3-redis, python3-git, python3-django-taggit, python3-zstandard
2424
Suggests: python3-mysqldb, python3-psycopg2, python3-pymemcache, memcached
2525
Description: Django-based patch status monitoring tool for linux systems.
2626
.

repos/repo_types/deb.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ def refresh_deb_repo(repo):
7171
are and then fetches and extracts packages from those files.
7272
"""
7373

74-
formats = ['Packages.xz', 'Packages.bz2', 'Packages.gz', 'Packages']
74+
formats = [
75+
'Packages.xz',
76+
'Packages.bz2',
77+
'Packages.gz',
78+
'Packages',
79+
]
7580

7681
ts = get_datetime_now()
7782
enabled_mirrors = repo.mirror_set.filter(refresh=True, enabled=True)

repos/repo_types/rpm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ def refresh_rpm_repo_mirrors(repo, errata_only=False):
5757
which type of repo it is, then refreshes the mirrors
5858
"""
5959
formats = [
60+
'repodata/repomd.xml.zst',
6061
'repodata/repomd.xml.xz',
6162
'repodata/repomd.xml.bz2',
6263
'repodata/repomd.xml.gz',
6364
'repodata/repomd.xml',
65+
'suse/repodata/repomd.xml.zst',
6466
'suse/repodata/repomd.xml.xz',
6567
'suse/repodata/repomd.xml.bz2',
6668
'suse/repodata/repomd.xml.gz',

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ redis==6.4.0
1919
django-celery-beat==2.7.0
2020
tqdm==4.67.1
2121
cvss==3.4
22+
zstandard==0.25.0

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ requires = /usr/bin/python3
2525
python3-importlib-metadata
2626
python3-cvss
2727
python3-redis
28+
python3-zstandard
2829
redis
2930
celery
3031
python3-django-celery-beat

util/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
import zlib
2222
import lzma
2323
import os
24+
try:
25+
# python 3.14+ - can also remove the dependency at that stage
26+
from compression import zstd
27+
except ImportError:
28+
import zstandard as zstd
2429
from datetime import datetime, timezone
2530
from enum import Enum
2631
from hashlib import md5, sha1, sha256, sha512
@@ -202,6 +207,16 @@ def unxz(contents):
202207
error_message.send(sender=None, text='lzma: ' + e)
203208

204209

210+
def unzstd(contents):
211+
""" unzstd contents in memory and return the data
212+
"""
213+
try:
214+
zstddata = zstd.ZstdDecompressor().stream_reader(contents).read()
215+
return zstddata
216+
except zstd.ZstdError as e:
217+
error_message.send(sender=None, text='zstd: ' + e)
218+
219+
205220
def extract(data, fmt):
206221
""" Extract the contents based on mimetype or file ending. Return the
207222
unmodified data if neither mimetype nor file ending matches, otherwise
@@ -214,6 +229,8 @@ def extract(data, fmt):
214229
m = magic.open(magic.MAGIC_MIME)
215230
m.load()
216231
mime = m.buffer(data).split(';')[0]
232+
if mime == 'application/zstd' or fmt.endswith('zst'):
233+
return unzstd(data)
217234
if mime == 'application/x-xz' or fmt.endswith('xz'):
218235
return unxz(data)
219236
elif mime == 'application/x-bzip2' or fmt.endswith('bz2'):

0 commit comments

Comments
 (0)