Skip to content

Commit

Permalink
Ensure that non-chunked exports also use compressionlevel=1
Browse files Browse the repository at this point in the history
closes pulp#4411
  • Loading branch information
dralley committed Sep 13, 2023
1 parent fdbe316 commit 8fe2f6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/4411.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure non-chunked exports also use gzip ``compressionlevel=1``
14 changes: 11 additions & 3 deletions pulpcore/app/tasks/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import os.path
import sys
import subprocess
import tarfile

Expand Down Expand Up @@ -414,8 +415,15 @@ def pulp_export(exporter_pk, params):
stdin=subprocess.PIPE,
) as split_process:
try:
with tarfile.open(tarfile_fp, "w|gz", fileobj=split_process.stdin) as tar:
_do_export(pulp_exporter, tar, the_export)
# on Python < 3.12 we have a monkeypatch which enables compression levels
if sys.version_info.major == 3 and sys.version_info.minor < 12:
with tarfile.open(tarfile_fp, "w|gz", fileobj=split_process.stdin) as tar:
_do_export(pulp_exporter, tar, the_export)
else:
with tarfile.open(
tarfile_fp, "w|gz", fileobj=split_process.stdin, compresslevel=1
) as tar:
_do_export(pulp_exporter, tar, the_export)
except Exception:
# no matter what went wrong, we can't trust the files we (may have) created.
# Delete the ones we can find and pass the problem up.
Expand All @@ -433,7 +441,7 @@ def pulp_export(exporter_pk, params):
else:
# write into the file
try:
with tarfile.open(tarfile_fp, "w:gz") as tar:
with tarfile.open(tarfile_fp, "w:gz", compresslevel=1) as tar:
_do_export(pulp_exporter, tar, the_export)
except Exception:
# no matter what went wrong, we can't trust the file we created.
Expand Down

0 comments on commit 8fe2f6c

Please sign in to comment.