With some errors, there is no point at all to keep trying.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
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;
}
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);
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 */
// 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);
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,
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;