From: Michael Tremer Date: Fri, 4 Jul 2025 15:54:11 +0000 (+0000) Subject: api: Serve debuginfo stuff X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e0a896eb1938f94bcde16ef598745e8c1a27f2e;p=pbs.git api: Serve debuginfo stuff Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 24567ece..97433b12 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/api/__init__.py b/src/api/__init__.py index 8d6e4019..1aab1d3e 100644 --- a/src/api/__init__.py +++ b/src/api/__init__.py @@ -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 index 00000000..8080c784 --- /dev/null +++ b/src/api/debuginfo.py @@ -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 . # +# # +############################################################################### + +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") diff --git a/src/buildservice/packages.py b/src/buildservice/packages.py index b319e63c..f8b2025d 100644 --- a/src/buildservice/packages.py +++ b/src/buildservice/packages.py @@ -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