From: Michael Tremer Date: Fri, 27 Jun 2025 07:16:50 +0000 (+0000) Subject: httpclient: Allow to configure the progress flags X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c2eccb4d5d84df71669a139f09b70e152645893d;p=pakfire.git httpclient: Allow to configure the progress flags This allows us to hide the progress bar when we are running API requests. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/client.c b/src/pakfire/client.c index 05f35258..1637a468 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -494,7 +494,7 @@ int pakfire_client_create(struct pakfire_client** client, goto ERROR; // Create a new HTTP client - r = pakfire_httpclient_create(&self->httpclient, self->ctx); + r = pakfire_httpclient_create(&self->httpclient, self->ctx, PAKFIRE_PROGRESS_NO_PROGRESS); if (r < 0) goto ERROR; diff --git a/src/pakfire/httpclient.c b/src/pakfire/httpclient.c index 1d4524fd..0aac81c6 100644 --- a/src/pakfire/httpclient.c +++ b/src/pakfire/httpclient.c @@ -646,14 +646,16 @@ static int pakfire_httpclient_setup_curl(struct pakfire_httpclient* self) { return 0; } -static int pakfire_httpclient_setup_progress(struct pakfire_httpclient* self) { +static int pakfire_httpclient_setup_progress(struct pakfire_httpclient* self, int flags) { int r; - const int flags = - PAKFIRE_PROGRESS_SHOW_PERCENTAGE | - PAKFIRE_PROGRESS_SHOW_ETA | - PAKFIRE_PROGRESS_SHOW_BYTES_TRANSFERRED | - PAKFIRE_PROGRESS_SHOW_TRANSFER_SPEED; + // Use some sensible defaults + if (!flags) + flags = + PAKFIRE_PROGRESS_SHOW_PERCENTAGE | + PAKFIRE_PROGRESS_SHOW_ETA | + PAKFIRE_PROGRESS_SHOW_BYTES_TRANSFERRED | + PAKFIRE_PROGRESS_SHOW_TRANSFER_SPEED; // Create a new progress indicator r = pakfire_progress_create(&self->progress, self->ctx, flags, NULL); @@ -694,7 +696,7 @@ static void pakfire_httpclient_free(struct pakfire_httpclient* self) { } int pakfire_httpclient_create(struct pakfire_httpclient** client, - struct pakfire_ctx* ctx) { + struct pakfire_ctx* ctx, int progress_flags) { struct pakfire_httpclient* self = NULL; int r; @@ -726,7 +728,7 @@ int pakfire_httpclient_create(struct pakfire_httpclient** client, goto ERROR; // Setup progress - r = pakfire_httpclient_setup_progress(self); + r = pakfire_httpclient_setup_progress(self, progress_flags); if (r) goto ERROR; diff --git a/src/pakfire/httpclient.h b/src/pakfire/httpclient.h index 18d4ba74..8031834b 100644 --- a/src/pakfire/httpclient.h +++ b/src/pakfire/httpclient.h @@ -26,7 +26,8 @@ struct pakfire_httpclient; #include #include -int pakfire_httpclient_create(struct pakfire_httpclient** client, struct pakfire_ctx* ctx); +int pakfire_httpclient_create(struct pakfire_httpclient** client, + struct pakfire_ctx* ctx, int progress_flags); struct pakfire_httpclient* pakfire_httpclient_ref(struct pakfire_httpclient* self); struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* self); diff --git a/src/pakfire/transaction.c b/src/pakfire/transaction.c index 4af17604..70d259b3 100644 --- a/src/pakfire/transaction.c +++ b/src/pakfire/transaction.c @@ -1999,7 +1999,7 @@ int pakfire_transaction_download(struct pakfire_transaction* transaction) { int r; // Initialize the HTTP client - r = pakfire_httpclient_create(&httpclient, transaction->ctx); + r = pakfire_httpclient_create(&httpclient, transaction->ctx, 0); if (r) { ERROR(transaction->ctx, "Could not initialize HTTP client: %m\n"); return 1; diff --git a/tests/libpakfire/httpclient.c b/tests/libpakfire/httpclient.c index 7ba9d0ce..a89cfd0b 100644 --- a/tests/libpakfire/httpclient.c +++ b/tests/libpakfire/httpclient.c @@ -31,7 +31,7 @@ static int test_create(const struct test* t) { int r = EXIT_FAILURE; // Create a HTTP client - ASSERT_SUCCESS(pakfire_httpclient_create(&client, t->ctx)); + ASSERT_SUCCESS(pakfire_httpclient_create(&client, t->ctx, 0)); // Everything passed r = EXIT_SUCCESS;