]> git.ipfire.org Git - pakfire.git/commitdiff
http: Add option for client code to skip mirrors
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 11 Dec 2016 22:13:19 +0000 (23:13 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 11 Dec 2016 22:13:19 +0000 (23:13 +0100)
In case any higher-level code is not satisfied with
a download (checksum doesn't match, data too old),
it can decide to skip the current mirror and the next
best one is chosen.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/http.py

index ec9aa3d7ab65b766fe8ee34d9ecf2fef3a38a828..5dace8e92ee9ecc55be97a4d5d4f74eff272f96d 100644 (file)
@@ -131,6 +131,25 @@ class Client(object):
                except IndexError as e:
                        raise DownloadError(_("No more mirrors to try")) from e
 
+       def skip_current_mirror(self):
+               """
+                       Called from a user of this class when a download
+                       was not acceptable (e.g. invalid checksum or too old
+                       metadata).
+
+                       It will drop the current mirror.
+
+                       If no mirrors are left, or no mirrors are available,
+                       it will raise DownloadError.
+               """
+               if not self.mirrors:
+                       raise DownloadError(_("No more mirrors to try"))
+
+               log.warning(_("Skipping mirror %s") % self.mirror)
+
+               self.mirrors.remove(self.mirror)
+               self._next_mirror()
+
        def _make_request(self, url, method="GET", data=None, auth=None, baseurl=None, mirror=None):
                # If a mirror is given, we use it as baseurl
                if mirror: