]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Refactor the xfer creation function
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 19:10:27 +0000 (19:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 19:10:27 +0000 (19:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/repo.c

index 6f4458d24c6bdab5f64c0752fe87d17005946605..54b87aa6b5abf0e1f6ff61ef669c357daeef1296 100644 (file)
@@ -235,6 +235,7 @@ static int __pakfire_repo_path(struct pakfire_repo* repo,
 static int pakfire_repo_xfer_create(
                struct pakfire_xfer** xfer, struct pakfire_repo* repo, const char* url, ...) {
        struct pakfire_mirrorlist* mirrorlist = NULL;
+       struct pakfire_xfer* x = NULL;
        const char* baseurl = NULL;
        va_list args;
        int r;
@@ -242,14 +243,14 @@ static int pakfire_repo_xfer_create(
        va_start(args, url);
 
        // Create a new transfer
-       r = pakfire_xfer_create(xfer, repo->ctx, url, args);
+       r = pakfire_xfer_create(&x, repo->ctx, url, args);
        if (r < 0)
                goto ERROR;
 
        // Set the baseurl
        baseurl = pakfire_repo_get_expanded_baseurl(repo);
        if (baseurl) {
-               r = pakfire_xfer_set_baseurl(*xfer, baseurl);
+               r = pakfire_xfer_set_baseurl(x, baseurl);
                if (r < 0)
                        goto ERROR;
        }
@@ -257,20 +258,19 @@ static int pakfire_repo_xfer_create(
        // Set the mirrorlist
        mirrorlist = pakfire_repo_get_mirrorlist(repo);
        if (mirrorlist) {
-               r = pakfire_xfer_set_mirrorlist(*xfer, mirrorlist);
+               r = pakfire_xfer_set_mirrorlist(x, mirrorlist);
                if (r < 0)
                        goto ERROR;
        }
 
+       // Success
+       *xfer = pakfire_xfer_ref(x);
+
 ERROR:
        if (mirrorlist)
                pakfire_mirrorlist_unref(mirrorlist);
-
-       // Destroy the xfer on error
-       if (r) {
-               if (*xfer)
-                       pakfire_xfer_unref(*xfer);
-       }
+       if (x)
+               pakfire_xfer_unref(x);
        va_end(args);
 
        return r;