]> git.ipfire.org Git - pbs.git/commitdiff
repos: Fix rendering the mirror list
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jan 2025 18:20:01 +0000 (18:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jan 2025 18:20:01 +0000 (18:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/mirrors.py
src/web/repos.py

index 60859ad12d96993e651ea9f27637d937e64ab914..5516ca0388486a1371f281913b45e2f0cf3ff768 100644 (file)
@@ -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
index 88c66d2bca0c5a42729c01f8d983bc028590d78e..4db0c49fb9c43bd06039bc7ffccc3858ce59094c 100644 (file)
@@ -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({