From: Michael Tremer Date: Wed, 22 Jan 2025 18:20:01 +0000 (+0000) Subject: repos: Fix rendering the mirror list X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec3170cb0b1188cee0d13ddb4d86328fa3795875;p=pbs.git repos: Fix rendering the mirror list Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/mirrors.py b/src/buildservice/mirrors.py index 60859ad1..5516ca03 100644 --- a/src/buildservice/mirrors.py +++ b/src/buildservice/mirrors.py @@ -76,7 +76,7 @@ class Mirrors(base.Object): return mirror - def get_mirrors_for_address(self, address): + async def get_mirrors_for_address(self, address): """ Returns all mirrors in random order with preferred mirrors first """ @@ -94,7 +94,7 @@ class Mirrors(base.Object): return r # Fetch all mirrors and shuffle them, but put preferred mirrors first - return sorted(self, key=__sort) + return sorted([mirror async for mirror in self], key=__sort) @functools.cached_property def location(self): @@ -272,7 +272,7 @@ class Mirror(database.Base, database.BackendMixin, database.SoftDeleteMixin): Returns True if this mirror is preferred for clients on the given network. """ # If the AS matches, we will prefer this - if self.asn and self.asn.number == network.asn: + if self.asn and self.asn == network.asn: return True # If the mirror and client are in the same country, we prefer this diff --git a/src/web/repos.py b/src/web/repos.py index 88c66d2b..4db0c49f 100644 --- a/src/web/repos.py +++ b/src/web/repos.py @@ -20,6 +20,8 @@ ############################################################################### import configparser +import os.path +import pakfire import tornado.web from . import base @@ -269,10 +271,10 @@ class DeleteHandler(BaseHandler): self.redirect("/distros/%s" % repo.distro.slug) -class MirrorlistHandler(BaseHandler): - def get(self, **kwargs): +class MirrorlistHandler(base.NoAuthMixin, BaseHandler): + async def get(self, **kwargs): # Fetch the repository - repo = self._get_repo(**kwargs) + repo = await self._get_repo(**kwargs) # Send nothing if repository isn't supposed to be mirrored if not repo.mirrored: @@ -281,18 +283,22 @@ class MirrorlistHandler(BaseHandler): # Fetch architecture arch = self.get_argument("arch") - mirrors = [] + # Check if we support the architecture + if not arch in pakfire.supported_arches(): + raise tornado.web.HTTPError(400, "Unsupported architecture: %s" % arch) # Fetch mirrors - for mirror in self.backend.mirrors.get_mirrors_for_address(self.current_address): - mirrors.append({ - "url" : "/".join((mirror.url, repo.path, arch)), + mirrors = [ + { + "url" : os.path.join(mirror.url, repo.path, arch), "location" : mirror.country_code, - }) + } + for mirror in await self.backend.mirrors.get_mirrors_for_address(self.current_address) + ] # Always use the buildservice itself as last resort mirrors.append({ - "url" : "/".join((repo.download_url, arch)), + "url" : os.path.join(repo.download_url, arch), }) self.finish({