]> git.ipfire.org Git - pakfire.git/commitdiff
mirrors: Evaluate the status code
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 Jan 2025 12:12:24 +0000 (12:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 Jan 2025 12:12:24 +0000 (12:12 +0000)
With some errors, there is no point at all to keep trying.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/mirror.c
src/pakfire/mirror.h
src/pakfire/xfer.c
src/pakfire/xfer.h

index 006ae321d7727fcad04ad6203cf45f3e4c1b9d07..7e2f9263ee6a9697bae673e34fe079931d3eda24 100644 (file)
@@ -118,7 +118,32 @@ void pakfire_mirror_mark_as_broken(struct pakfire_mirror* mirror) {
        mirror->is_broken = 1;
 }
 
-void pakfire_mirror_xfer_failed(struct pakfire_mirror* mirror) {
-       if (!mirror->retries_left--)
-               pakfire_mirror_mark_as_broken(mirror);
+/*
+       This function is called when a transfer has failed and will automatically
+       disable the mirror.
+*/
+int pakfire_mirror_xfer_failed(struct pakfire_mirror* self, pakfire_xfer_error_code_t code) {
+       switch (code) {
+               // We should never be called with this
+               case PAKFIRE_XFER_OK:
+                       return -EINVAL;
+
+               /*
+                       The mirror seems to have responded with something
+                       like 502 or 503, so there is no point in tryin again.
+               */
+               case PAKFIRE_XFER_TRANSPORT_ERROR:
+                       pakfire_mirror_mark_as_broken(self);
+                       break;
+
+               /*
+                       For all other errors, we will just count down.
+               */
+               default:
+                       if (!self->retries_left--)
+                               pakfire_mirror_mark_as_broken(self);
+                       break;
+       }
+
+       return 0;
 }
index ab2d4615da3bd1f26e2fa2debe8193d597ad7f2d..abc44318f0c1d97865a8b641b7111bda89e11a1e 100644 (file)
@@ -24,6 +24,7 @@
 struct pakfire_mirror;
 
 #include <pakfire/ctx.h>
+#include <pakfire/xfer.h>
 
 int pakfire_mirror_create(struct pakfire_mirror** mirror,
        struct pakfire_ctx* ctx, const char* url);
@@ -38,6 +39,6 @@ const char* pakfire_mirror_get_url(struct pakfire_mirror* mirror);
 int pakfire_mirror_is_broken(struct pakfire_mirror* mirror);
 void pakfire_mirror_mark_as_broken(struct pakfire_mirror* mirror);
 
-void pakfire_mirror_xfer_failed(struct pakfire_mirror* mirror);
+int pakfire_mirror_xfer_failed(struct pakfire_mirror* self, pakfire_xfer_error_code_t code);
 
 #endif /* PAKFIRE_MIRROR_H */
index cf291164865b0fc0f0979ff745e682e6a58a751b..f2582c68e45ec8e62f27fcf542a2a85998fa5477 100644 (file)
@@ -972,7 +972,10 @@ static int pakfire_xfer_fail(struct pakfire_xfer* xfer, int code) {
 
        // Did we use a mirror?
        if (xfer->mirror) {
-               pakfire_mirror_xfer_failed(xfer->mirror);
+               // Tell the mirror about the failure
+               r = pakfire_mirror_xfer_failed(xfer->mirror, code);
+               if (r < 0)
+                       return r;
 
                // Select the next mirror
                r = pakfire_xfer_next_mirror(xfer);
index 1b0bf86fcf021cdeb5290b5d22319a6f536fefc8..a1746a6e97c3f2b139d416c7d9381b49639dfa82 100644 (file)
 
 struct pakfire_xfer;
 
-#include <pakfire/ctx.h>
-#include <pakfire/httpclient.h>
-#include <pakfire/mirrorlist.h>
-#include <pakfire/progress.h>
-
 typedef enum pakfire_xfer_error_code {
        PAKFIRE_XFER_OK = 0,
 
@@ -71,6 +66,11 @@ typedef enum pakfire_xfer_error_code {
        PAKFIRE_XFER_DIGEST_MISMATCH,
 } pakfire_xfer_error_code_t;
 
+#include <pakfire/ctx.h>
+#include <pakfire/httpclient.h>
+#include <pakfire/mirrorlist.h>
+#include <pakfire/progress.h>
+
 typedef enum pakfire_xfer_flags {
        PAKFIRE_XFER_NO_PROGRESS = (1 << 0),
 } pakfire_xfer_flags_t;