// Timer
sd_event_source* timer;
+ // Progress
+ struct pakfire_progress* progress;
+
int parallel;
// cURL share handle
return 0;
}
+static int pakfire_httpclient_setup_progress(struct pakfire_httpclient* client) {
+ int r;
+
+ const int 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(&client->progress, client->ctx, flags, NULL);
+ if (r)
+ return r;
+
+ return 0;
+}
+
static void pakfire_httpclient_free(struct pakfire_httpclient* client) {
struct pakfire_xfer_element* x = NULL;
pakfire_httpclient_xfer_free(x);
}
+ if (client->progress)
+ pakfire_progress_unref(client->progress);
if (client->share)
curl_share_cleanup(client->share);
if (client->curl)
if (r)
goto ERROR;
+ // Setup progress
+ r = pakfire_httpclient_setup_progress(c);
+ if (r)
+ goto ERROR;
+
// Success
*client = c;
}
int pakfire_httpclient_run(struct pakfire_httpclient* client, const char* title) {
- struct pakfire_progress* progress = NULL;
- int progress_flags =
- PAKFIRE_PROGRESS_SHOW_PERCENTAGE |
- PAKFIRE_PROGRESS_SHOW_ETA;
int r = 0;
struct pakfire_xfer_element* x = NULL;
// Fetch the total downloadsize
const size_t downloadsize = pakfire_httpclient_total_downloadsize(client);
- // If we know the downloadsize, we can show more details
- if (downloadsize) {
- progress_flags |=
- PAKFIRE_PROGRESS_SHOW_BYTES_TRANSFERRED |
- PAKFIRE_PROGRESS_SHOW_TRANSFER_SPEED;
- } else {
- progress_flags |=
- PAKFIRE_PROGRESS_SHOW_COUNTER;
- }
-
// Fetch the total number of queued transfers
const unsigned int num_queued_xfers = pakfire_httpclient_total_queued_xfers(client);
- // Create a new progress indicator
- r = pakfire_progress_create(&progress, client->ctx, progress_flags, NULL);
+ // Set the title
+ r = pakfire_progress_set_title(client->progress, title);
if (r)
goto ERROR;
- // Set the title
- if (title) {
- r = pakfire_progress_set_title(progress, title);
- if (r)
- goto ERROR;
- }
-
// Start the progress
- r = pakfire_progress_start(progress, (downloadsize) ? downloadsize : num_queued_xfers);
+ r = pakfire_progress_start(client->progress, (downloadsize) ? downloadsize : num_queued_xfers);
if (r)
goto ERROR;
// Make sure that we have up to parallel transfers active
- r = pakfire_httpclient_start_transfers(client, progress);
+ r = pakfire_httpclient_start_transfers(client, client->progress);
if (r)
goto ERROR;
} while (client->still_running > 0);
// We are finished!
- r = pakfire_progress_finish(progress);
+ r = pakfire_progress_finish(client->progress);
if (r)
goto ERROR;
pakfire_xfer_fail(x->xfer);
}
- if (progress)
- pakfire_progress_unref(progress);
-
return r;
}