From 8fe2f6cc3658f648ba43d3a73bfbc6c6d5f275f5 Mon Sep 17 00:00:00 2001 From: Daniel Alley Date: Tue, 12 Sep 2023 20:16:53 -0400 Subject: [PATCH] Ensure that non-chunked exports also use compressionlevel=1 closes #4411 --- CHANGES/4411.bugfix | 1 + pulpcore/app/tasks/export.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 CHANGES/4411.bugfix diff --git a/CHANGES/4411.bugfix b/CHANGES/4411.bugfix new file mode 100644 index 0000000000..4a0cfd5db5 --- /dev/null +++ b/CHANGES/4411.bugfix @@ -0,0 +1 @@ +Ensure non-chunked exports also use gzip ``compressionlevel=1`` \ No newline at end of file diff --git a/pulpcore/app/tasks/export.py b/pulpcore/app/tasks/export.py index fbf25b1e86..49d597c1ee 100644 --- a/pulpcore/app/tasks/export.py +++ b/pulpcore/app/tasks/export.py @@ -3,6 +3,7 @@ import logging import os import os.path +import sys import subprocess import tarfile @@ -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. @@ -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.