]> git.ipfire.org Git - people/jschlag/pbs.git/commitdiff
mirrors: Do not deliver mirror list for non-mirrored repos
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 22 Oct 2017 21:57:45 +0000 (22:57 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 22 Oct 2017 21:57:45 +0000 (22:57 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/handlers.py

index 6f4b2a8e325f01b6ce7330c3cb082583783fea9e..a92ab0bb18cd4e0cc57568afe09e3b874f00d766 100644 (file)
@@ -201,6 +201,10 @@ class RepositoryMirrorlistHandler(BaseHandler):
                if not repo:
                        raise tornado.web.HTTPError(404)
 
+               # Send nothing if repository isn't supposed to be mirrored
+               if not repo.mirrored:
+                       raise tornado.web.HTTPError(404)
+
                # This is a plaintext file.
                self.set_header("Content-Type", "text/plain")
 
@@ -216,51 +220,27 @@ class RepositoryMirrorlistHandler(BaseHandler):
                # A list with mirrors that are sent to the user.
                mirrors = []
 
-               # Only search for mirrors on repositories that are supposed to be found
-               # on mirror servers.
-
-               if repo.mirrored:
-                       # Select a list of preferred mirrors
-                       for mirror in self.mirrors.get_for_location(self.current_address):
-                               mirrors.append({
-                                       "url"       : "/".join((mirror.url, distro.identifier, repo.identifier, arch)),
-                                       "location"  : mirror.country_code,
-                                       "preferred" : 1,
-                               })
-
-                       # Add all other mirrors at the end in a random order
-                       remaining_mirrors = [m for m in self.backend.mirrors if not m in mirrors]
-                       random.shuffle(remaining_mirrors)
-
-                       for mirror in remaining_mirrors:
-                               mirrors.append({
-                                       "url"       : "/".join((mirror.url, distro.identifier, repo.identifier, arch)),
-                                       "location"  : mirror.country_code,
-                                       "preferred" : 0,
-                               })
-
-               else:
-                       repo_baseurl = self.pakfire.settings.get("repository_baseurl")
-                       if repo_baseurl.endswith("/"):
-                               repo_baseurl = repo_baseurl[:-1]
-
-                       for mirror in self.mirrors.get_all():
-                               print mirror.url, repo_baseurl
-                               if not mirror.url == repo_baseurl:
-                                       continue
-
-                               mirror = {
-                                       "url"       : "/".join((mirror.url, distro.identifier, repo.identifier, arch)),
-                                       "location"  : mirror.country_code,
-                                       "preferred" : 0,
-                               }
-
-                               mirrors.append(mirror)
-                               break
+               # Select a list of preferred mirrors
+               for mirror in self.mirrors.get_for_location(self.current_address):
+                       mirrors.append({
+                               "url"       : "/".join((mirror.url, distro.identifier, repo.identifier, arch)),
+                               "location"  : mirror.country_code,
+                               "preferred" : 1,
+                       })
+
+               # Add all other mirrors at the end in a random order
+               remaining_mirrors = [m for m in self.backend.mirrors if not m in mirrors]
+               random.shuffle(remaining_mirrors)
+
+               for mirror in remaining_mirrors:
+                       mirrors.append({
+                               "url"       : "/".join((mirror.url, distro.identifier, repo.identifier, arch)),
+                               "location"  : mirror.country_code,
+                               "preferred" : 0,
+                       })
 
                ret["mirrors"] = mirrors
-               self.write(ret)
-               
+               self.finish(ret)
 
 
 class RepoActionHandler(BaseHandler):