1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

lib/dload.c: Fix progress callback issues on download

Use a static variable to effectively track the initialization state of
the progress callback via the last byte amount reported as downloaded by
libcurl.

Signed-off-by: Dave Reisner <d@falconindy.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dave Reisner 2011-03-17 09:01:30 -04:00 committed by Dan McGee
parent 768451c5e3
commit 82fb7a0202

View File

@ -42,9 +42,12 @@
#include "util.h" #include "util.h"
#include "handle.h" #include "handle.h"
static int prevprogress; /* last download amount */ #ifdef HAVE_LIBCURL
static double prevprogress; /* last download amount */
#endif
static char *get_filename(const char *url) { static char *get_filename(const char *url)
{
char *filename = strrchr(url, '/'); char *filename = strrchr(url, '/');
if(filename != NULL) { if(filename != NULL) {
filename++; filename++;
@ -96,6 +99,14 @@ static int curl_progress(void *filename, double dltotal, double dlnow,
return 0; return 0;
} }
/* initialize the progress bar here to avoid displaying it when
* a repo is up to date and nothing gets downloaded */
if(DOUBLE_EQ(prevprogress, 0)) {
if(handle->dlcb) {
handle->dlcb((const char*)filename, 0, (long)dltotal);
}
}
if(dload_interrupted) { if(dload_interrupted) {
return 1; return 1;
} }
@ -214,9 +225,8 @@ static int curl_download_internal(const char *url, const char *localpath,
sigaction(SIGINT, NULL, &sig_int[OLD]); sigaction(SIGINT, NULL, &sig_int[OLD]);
sigaction(SIGINT, &sig_int[NEW], NULL); sigaction(SIGINT, &sig_int[NEW], NULL);
/* set initial value of prevprogress to -1 which causes curl_progress() to /* Progress 0 - initialize */
* initialize the progress bar with 0% once. */ prevprogress = 0;
prevprogress = -1;
/* perform transfer */ /* perform transfer */
handle->curlerr = curl_easy_perform(handle->curl); handle->curlerr = curl_easy_perform(handle->curl);