]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Import log files as they are when they are already compressed
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 3 Feb 2025 10:12:54 +0000 (10:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 3 Feb 2025 10:12:54 +0000 (10:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py
src/buildservice/uploads.py

index 0d94f89f72fb85efed8f29759d84033324a0ffd4..f5fd608b80232eba008eb164c81cd5d0c597fbce 100644 (file)
@@ -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
index 07de87159cddb8a4ea8201dc2a816d2e6406d239..7e827f4a62ff31e87126dd7f5f3a15c94111ce17 100644 (file)
@@ -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)