From 230703d73dea267f1c87ea459cf757e96d7b0959 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 3 Feb 2025 10:12:54 +0000 Subject: [PATCH] jobs: Import log files as they are when they are already compressed Signed-off-by: Michael Tremer --- src/buildservice/jobs.py | 9 ++++++++- src/buildservice/uploads.py | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 0d94f89f..f5fd608b 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -1042,7 +1042,14 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin): await self.backend.make_parent_directory(path) # Open the destination path - with gzip.open(path, "wb", compresslevel=9) as f: + f = open(path, "wb") + + # If the upload was not compressed already, compress it + if not upload.extension == "gz": + f = gzip.GzipFile(fileobj=f, compresslevel=9) + + # Copy the payload + with f: await upload.copyinto(f) # Store everything in the database diff --git a/src/buildservice/uploads.py b/src/buildservice/uploads.py index 07de8715..7e827f4a 100644 --- a/src/buildservice/uploads.py +++ b/src/buildservice/uploads.py @@ -140,6 +140,14 @@ class Upload(database.Base, database.BackendMixin): filename = Column(Text, nullable=False) + # Extension + + @property + def extension(self): + filename, ext = os.path.splitext(self.filename) + + return ext.removeprefix(".") + # Path path = Column(Text, nullable=False) -- 2.47.3