]> git.ipfire.org Git - pbs.git/commitdiff
api: Serve debuginfo stuff
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 4 Jul 2025 15:54:11 +0000 (15:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 4 Jul 2025 15:54:11 +0000 (15:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/api/__init__.py
src/api/debuginfo.py [new file with mode: 0644]
src/buildservice/packages.py

index 24567ece9fea8994faa44b75decac5bf029a0111..97433b12e8e5cd9c0727e9a3ad3e8eb51b108cea 100644 (file)
@@ -124,6 +124,7 @@ api_PYTHON = \
        src/api/auth.py \
        src/api/builders.py \
        src/api/builds.py \
+       src/api/debuginfo.py \
        src/api/distros.py \
        src/api/downloads.py \
        src/api/events.py \
index 8d6e4019bb03cecc4b28d957b5207b8421700659..1aab1d3e77ed2622a9cb29e7f603520a42cf03d7 100644 (file)
@@ -54,6 +54,7 @@ apiv1 = fastapi.APIRouter(
 from . import auth
 from . import builders
 from . import builds
+from . import debuginfo
 from . import distros
 from . import downloads
 from . import events
diff --git a/src/api/debuginfo.py b/src/api/debuginfo.py
new file mode 100644 (file)
index 0000000..8080c78
--- /dev/null
@@ -0,0 +1,54 @@
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2025 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import asyncio
+import fastapi
+
+from . import app
+from . import backend
+
+# XXX This endpoint need some ratelimiting applied
+
+@app.get("/buildid/{buildid}/debuginfo", include_in_schema=False)
+async def get(buildid: str) -> fastapi.responses.StreamingResponse:
+       # Fetch the package
+       package = await backend.packages.get_by_buildid(buildid)
+       if not package:
+               raise fastapi.HTTPException(404, "Could not find package providing BuildID %s" % buildid)
+
+       # Fetch the debuginfo
+       file = await package.get_debuginfo(buildid)
+       if not file:
+               raise fastapi.HTTPException(404, "Could not find debuginfo in %s" % package)
+
+       # Create a helper function that will stream the file chunk by chunk
+       async def stream():
+               f = await file.open()
+
+               while True:
+                       chunk = await asyncio.to_thread(f.read, 128 * 1024)
+                       if not chunk:
+                               break
+
+                       yield chunk
+
+       # Stream the payload
+       return fastapi.responses.StreamingResponse(
+               stream(), media_type="application/octet-stream")
index b319e63c55076c07b54b5eb03490de09ca0112e8..f8b2025dd2c8a7010355133b837fc3ce8861633b 100644 (file)
@@ -82,7 +82,7 @@ class Packages(base.Object):
                path = buildid_to_path(buildid)
 
                # Search for the package containing this file
-               async for package in self.search_by_filename(path, limit=1):
+               for package in await self.search_by_filename(path, limit=1):
                        log.debug("Found debuginfo for %s in %s" % (buildid, package))
 
                        return package
@@ -643,7 +643,9 @@ class File(sqlmodel.SQLModel, table=True):
 
        # Package
 
-       package: "Package" = sqlmodel.Relationship()
+       package: "Package" = sqlmodel.Relationship(
+               sa_relationship_kwargs={ "lazy" : "selectin", },
+       )
 
        # Path