From: Michael Tremer Date: Fri, 6 Oct 2023 15:02:23 +0000 (+0000) Subject: packages: Implement sending debuginfo X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a1b84313963f0695202253dc3c6b2b810c7008a;p=pbs.git packages: Implement sending debuginfo Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 88052273..1d506fbc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -129,6 +129,7 @@ web_PYTHON = \ src/web/bugs.py \ src/web/builders.py \ src/web/builds.py \ + src/web/debuginfo.py \ src/web/distributions.py \ src/web/errors.py \ src/web/events.py \ diff --git a/src/buildservice/packages.py b/src/buildservice/packages.py index 4c2d10c8..d0d71408 100644 --- a/src/buildservice/packages.py +++ b/src/buildservice/packages.py @@ -78,6 +78,19 @@ class Packages(base.Object): """, uuid, ) + async def get_by_buildid(self, buildid): + """ + Fetches the debug information for the given BuildID + """ + # Make the path + path = buildid_to_path(buildid) + + # Search for the package containing this file + for package in self.search_by_filename(path, limit=1): + log.debug("Found debuginfo for %s in %s" % (buildid, package)) + + return package + async def create(self, upload, distro=None, commit=None): """ Creates a new package from an uploaded file @@ -620,6 +633,11 @@ class Package(base.DataObject): """, self.id, path, ) + def get_debuginfo(self, buildid): + path = buildid_to_path(buildid) + + return self.get_file(path) + # Open async def open(self): @@ -766,3 +784,10 @@ class File(base.Object): # Read everything in a separate thread return await asyncio.to_thread(f.readall) + + +def buildid_to_path(buildid): + """ + Returns the path where we expect to find the BuildID + """ + return "/usr/lib/debug/.build-id/%s/%s.debug" % (buildid[0:2], buildid[2:]) diff --git a/src/web/__init__.py b/src/web/__init__.py index 7ea0eab5..daedd8bc 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -16,6 +16,7 @@ from . import auth from . import bugs from . import builders from . import builds +from . import debuginfo from . import distributions from . import errors from . import events @@ -246,6 +247,9 @@ class Application(tornado.web.Application): # Log (r"/log", handlers.LogHandler), + # Debuginfo + (r"/buildid/([0-9a-f]{40})/debuginfo", debuginfo.DebugInfoHandler), + # Repositories (r"/api/v1/repos/([\w\d\-]+)", repos.APIv1IndexHandler), (r"/api/v1/repos/([\w\d\-]+)/([\w\d\-]+)", repos.APIv1ShowHandler), diff --git a/src/web/debuginfo.py b/src/web/debuginfo.py new file mode 100644 index 00000000..a3b14748 --- /dev/null +++ b/src/web/debuginfo.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 + +import tornado.web + +from . import base + +class DebugInfoHandler(base.BaseHandler): + async def get(self, buildid): + package = await self.backend.packages.get_by_buildid(buildid) + if not package: + raise tornado.web.HTTPError(404, "Could not find package providing BuildID %s" % buildid) + + # Fetch the debuginfo + file = package.get_debuginfo(buildid) + if not file: + raise tornado.web.HTTPError(404, "Could not find debuginfo in %s" % package) + + # Send the payload + await file.sendfile(self)