]> git.ipfire.org Git - pakfire.git/commitdiff
client: Refactor deleting repositories
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 08:28:27 +0000 (08:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 08:28:27 +0000 (08:28 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/repo_delete.c
src/pakfire/client.c

index 49a5c08d0a76ab707b226d81fb9f5fc58dd941da..c8a93dec337873b8cb256532375e54ace4b6daf3 100644 (file)
@@ -60,33 +60,24 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
        return 0;
 }
 
+static int ready_callback(struct pakfire_client* client, void* data) {
+       const struct cli_local_args* local_args = data;
+
+       // Delete the repository
+       return pakfire_client_delete_repo(client,
+               local_args->distro, local_args->name);
+}
+
 int cli_repo_delete(void* data, int argc, char* argv[]) {
        struct cli_global_args* global_args = data;
        struct cli_local_args local_args = {};
-       struct pakfire_client* client = NULL;
-       struct json_object* repo = NULL;
        int r;
 
        // Parse the command line
        r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args);
        if (r)
-               goto ERROR;
-
-       // Connect to the build service
-       r = cli_setup_client(&client, global_args);
-       if (r < 0)
-               goto ERROR;
-
-       // Delete the repository
-       r = pakfire_client_delete_repo(client, local_args.distro, local_args.name);
-       if (r)
-               goto ERROR;
-
-ERROR:
-       if (client)
-               pakfire_client_unref(client);
-       if (repo)
-               json_object_put(repo);
+               return r;
 
-       return r;
+       // Run the client
+       return cli_run_client(global_args, ready_callback, &local_args);
 }
index 17d267d2aafb6761c2cd5e27741bec99cca276da..d20344e6a8f9c47602fb99e47829e3ab4b4c8129 100644 (file)
@@ -1479,22 +1479,24 @@ int pakfire_client_delete_repo(struct pakfire_client* self,
 
        // Create a new xfer
        r = pakfire_client_xfer_create(&xfer, self, "/api/v1/repos/%s/%s", distro, name);
-       if (r)
+       if (r < 0)
                goto ERROR;
 
        // Ask to DELETE
        r = pakfire_xfer_set_method(xfer, PAKFIRE_METHOD_DELETE);
-       if (r)
+       if (r < 0)
                goto ERROR;
 
        // Enable authentication
        r = pakfire_client_xfer_auth(self, xfer);
-       if (r)
+       if (r < 0)
                goto ERROR;
 
-       // Send the request
-       r = pakfire_xfer_run_api_request(xfer, NULL, NULL);
-       if (r)
+       // XXX This needs a callback
+
+       // Enqueue the transfer
+       r = pakfire_httpclient_enqueue(self->httpclient, xfer);
+       if (r < 0)
                goto ERROR;
 
 ERROR: