From: Michael Tremer Date: Mon, 3 Feb 2025 10:12:54 +0000 (+0000) Subject: jobs: Import log files as they are when they are already compressed X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=230703d73dea267f1c87ea459cf757e96d7b0959;p=pbs.git jobs: Import log files as they are when they are already compressed Signed-off-by: Michael Tremer --- 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)