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

index 1c7c84fed21f5d519880fe499e61bd1ba5eb149f..cf91e295154ed9d3a450b870accbcddd06820d8f 100644 (file)
@@ -73,11 +73,18 @@ 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;
+
+       // Create the repository
+       return pakfire_client_create_repo(client,
+               local_args->distro, local_args->name, local_args->description);
+}
+
 int cli_repo_create(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
@@ -90,22 +97,15 @@ int cli_repo_create(void* data, int argc, char* argv[]) {
        if (r < 0)
                goto ERROR;
 
-       // List repos
-       r = pakfire_client_create_repo(client, local_args.distro, local_args.name,
-                       local_args.description, &repo);
-       if (r)
-               goto ERROR;
+       // Set ready callback
+       pakfire_client_set_ready_callback(client, ready_callback, &local_args);
 
-       // Dump everything
-       r = cli_dump_json(repo);
-       if (r)
-               goto ERROR;
+       // Run the client
+       r = pakfire_client_run(client);
 
 ERROR:
        if (client)
                pakfire_client_unref(client);
-       if (repo)
-               json_object_put(repo);
 
        return r;
 }
index 715a6bd538f10790ad10d5a9bff906ae390f3f9a..17d267d2aafb6761c2cd5e27741bec99cca276da 100644 (file)
@@ -1415,10 +1415,9 @@ ERROR:
 }
 
 int pakfire_client_create_repo(struct pakfire_client* self,
-               const char* distro, const char* name, const char* description, struct json_object** p) {
+               const char* distro, const char* name, const char* description) {
        struct pakfire_xfer* xfer = NULL;
        struct json_object* request = NULL;
-       struct json_object* response = NULL;
        int r;
 
        // Check inputs
@@ -1427,12 +1426,12 @@ int pakfire_client_create_repo(struct pakfire_client* self,
 
        // Create a new xfer
        r = pakfire_client_xfer_create(&xfer, self, "/api/v1/repos/%s", distro);
-       if (r)
+       if (r < 0)
                goto ERROR;
 
        // Enable authentication
        r = pakfire_client_xfer_auth(self, xfer);
-       if (r)
+       if (r < 0)
                goto ERROR;
 
        // Create the request
@@ -1442,32 +1441,33 @@ int pakfire_client_create_repo(struct pakfire_client* self,
 
        // Set name
        r = pakfire_json_add_string(request, "name", name);
-       if (r)
+       if (r < 0)
                goto ERROR;
 
        // Set description
        if (description) {
                r = pakfire_json_add_string(request, "description", description);
-               if (r)
+               if (r < 0)
                        goto ERROR;
        }
 
-       // Send the request
-       r = pakfire_xfer_run_api_request(xfer, request, &response);
-       if (r)
+       // Set the request body
+       r = pakfire_xfer_set_json_payload(xfer, request);
+       if (r < 0)
                goto ERROR;
 
-       // Return the pointer
-       if (p)
-               *p = json_object_get(response);
+       // XXX This needs a callback
+
+       // Enqueue the transfer
+       r = pakfire_httpclient_enqueue(self->httpclient, xfer);
+       if (r < 0)
+               goto ERROR;
 
 ERROR:
        if (xfer)
                pakfire_xfer_unref(xfer);
        if (request)
                json_object_put(request);
-       if (response)
-               json_object_put(response);
 
        return r;
 }
index a977da2a899ecb45c4139a952da8d6f2dbaa9609..10d03e18164658360a7712094b7e89115c6cba8b 100644 (file)
@@ -109,7 +109,7 @@ int pakfire_client_list_repos(struct pakfire_client* client,
 int pakfire_client_get_repo(struct pakfire_client* client,
        const char* distro, const char* name, struct json_object** repo);
 int pakfire_client_create_repo(struct pakfire_client* client,
-       const char* distro, const char* name, const char* description, struct json_object** repo);
+       const char* distro, const char* name, const char* description);
 int pakfire_client_delete_repo(struct pakfire_client* client,
        const char* distro, const char* name);