From 30a2a19cb34b6c8e72dccb3b0fb50da203b752f1 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 22 Oct 2017 22:57:45 +0100 Subject: [PATCH] mirrors: Do not deliver mirror list for non-mirrored repos Signed-off-by: Michael Tremer --- src/web/handlers.py | 66 ++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/src/web/handlers.py b/src/web/handlers.py index 6f4b2a8..a92ab0b 100644 --- a/src/web/handlers.py +++ b/src/web/handlers.py @@ -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): -- 2.39.2