return xfer->effective_url;
}
+/*
+ Helper function to set a chosen mirror
+*/
+static int pakfire_xfer_select_mirror(struct pakfire_xfer* self, struct pakfire_mirror* mirror) {
+ // Free the previous mirror
+ if (self->mirror) {
+ pakfire_mirror_unref(self->mirror);
+ self->mirror = NULL;
+ }
+
+ // Set the new mirror (if available)
+ if (mirror) {
+ DEBUG(self->ctx, "Selected mirror %s\n", pakfire_mirror_get_url(mirror));
+
+ self->mirror = pakfire_mirror_ref(mirror);
+ }
+
+ return 0;
+}
+
int pakfire_xfer_set_mirrorlist(struct pakfire_xfer* xfer, struct pakfire_mirrorlist* mirrors) {
+ struct pakfire_mirror* mirror = NULL;
+ int r;
+
// Drop all references to a former mirrorlist
if (xfer->mirrors) {
pakfire_mirrorlist_unref(xfer->mirrors);
xfer->mirrors = NULL;
}
- // Drop all references to the formerly selected mirror
- if (xfer->mirror) {
- pakfire_mirror_unref(xfer->mirror);
- xfer->mirror = NULL;
- }
-
// If a new list was passed, we store a reference to it
if (mirrors) {
xfer->mirrors = pakfire_mirrorlist_ref(mirrors);
// Select the first mirror from the list
- xfer->mirror = pakfire_mirrorlist_get_first(xfer->mirrors);
+ mirror = pakfire_mirrorlist_get_first(xfer->mirrors);
}
- return 0;
+ // Select the mirror (or reset if NULL)
+ r = pakfire_xfer_select_mirror(xfer, mirror);
+ if (r < 0)
+ goto ERROR;
+
+ERROR:
+ if (mirror)
+ pakfire_mirror_unref(mirror);
+
+ return r;
}
// Size
}
}
+/*
+ Called after something went wrong and we want to try again with another mirror
+*/
static int pakfire_xfer_next_mirror(struct pakfire_xfer* xfer) {
struct pakfire_mirror* mirror = NULL;
+ int r = 0;
// If our mirror is broken, we select the next one
if (xfer->mirror) {
// Choose the next mirror
mirror = pakfire_mirrorlist_get_next(xfer->mirrors, xfer->mirror);
- // Free the previous mirror
- pakfire_mirror_unref(xfer->mirror);
-
// Store the new mirror
- if (mirror) {
- DEBUG(xfer->ctx, "Selected mirror %s\n", pakfire_mirror_get_url(mirror));
-
- xfer->mirror = pakfire_mirror_ref(mirror);
-
- // If we could not find a mirror, we clear the pointer
- } else {
- xfer->mirror = NULL;
- }
+ r = pakfire_xfer_select_mirror(xfer, mirror);
+ if (r < 0)
+ goto ERROR;
}
- // Cleanup
+ERROR:
if (mirror)
pakfire_mirror_unref(mirror);
- return 0;
+ return r;
}
static int pakfire_xfer_fail(struct pakfire_xfer* xfer, int code) {