Skip to content

Commit 4eb6b3f

Browse files
committed
add support for zstd compression in deb and rpm repos
fixes: #698 Signed-off-by: Marcus Furlong <furlongm@gmail.com>
1 parent 3f8756c commit 4eb6b3f

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-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-zstd
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ 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.zst',
76+
'Packages.xz',
77+
'Packages.bz2',
78+
'Packages.gz',
79+
'Packages',
80+
]
7581

7682
ts = get_datetime_now()
7783
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==5.2.1
1919
django-celery-beat==2.7.0
2020
tqdm==4.67.1
2121
cvss==3.4
22+
zstd==1.5.7.2

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-zstd
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
@@ -20,6 +20,11 @@
2020
import magic
2121
import zlib
2222
import lzma
23+
try:
24+
# python 3.14+ - can also remove the dependency at that stage
25+
from compression import zstd
26+
except ImportError:
27+
import zstd
2328
from datetime import datetime, timezone
2429
from enum import Enum
2530
from hashlib import md5, sha1, sha256, sha512
@@ -191,6 +196,16 @@ def unxz(contents):
191196
error_message.send(sender=None, text='lzma: ' + e)
192197

193198

199+
def unzstd(contents):
200+
""" unzstd contents in memory and return the data
201+
"""
202+
try:
203+
zstddata = zstd.decompress(contents)
204+
return zstddata
205+
except zstd.ZstdError as e:
206+
error_message.send(sender=None, text='zstd: ' + e)
207+
208+
194209
def extract(data, fmt):
195210
""" Extract the contents based on mimetype or file ending. Return the
196211
unmodified data if neither mimetype nor file ending matches, otherwise
@@ -203,6 +218,8 @@ def extract(data, fmt):
203218
m = magic.open(magic.MAGIC_MIME)
204219
m.load()
205220
mime = m.buffer(data).split(';')[0]
221+
if mime == 'application/zstd' or fmt.endswith('zstd'):
222+
return unzstd(data)
206223
if mime == 'application/x-xz' or fmt.endswith('xz'):
207224
return unxz(data)
208225
elif mime == 'application/x-bzip2' or fmt.endswith('bz2'):

0 commit comments

Comments
 (0)