move prevprogress onto payload handle

This is a poor place for it, and it will likely move again in the
future, but it's better to have it here than as a static variable.

Initialization of this variable is now no longer necessary as its
zeroed on creation of the payload struct.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dave Reisner 2011-09-29 12:17:16 -04:00 committed by Dan McGee
parent 775b94e649
commit ad8d3ceb89
2 changed files with 4 additions and 8 deletions

View file

@ -43,8 +43,6 @@
#include "handle.h" #include "handle.h"
#ifdef HAVE_LIBCURL #ifdef HAVE_LIBCURL
static off_t prevprogress; /* last download amount */
static const char *get_filename(const char *url) static const char *get_filename(const char *url)
{ {
char *filename = strrchr(url, '/'); char *filename = strrchr(url, '/');
@ -112,19 +110,19 @@ static int curl_progress(void *file, double dltotal, double dlnow,
total_size = payload->initial_size + (off_t)dltotal; total_size = payload->initial_size + (off_t)dltotal;
if(DOUBLE_EQ(dltotal, 0.0) || prevprogress == total_size) { if(DOUBLE_EQ(dltotal, 0.0) || payload->prevprogress == total_size) {
return 0; return 0;
} }
/* initialize the progress bar here to avoid displaying it when /* initialize the progress bar here to avoid displaying it when
* a repo is up to date and nothing gets downloaded */ * a repo is up to date and nothing gets downloaded */
if(prevprogress == 0) { if(payload->prevprogress == 0) {
payload->handle->dlcb(payload->remote_name, 0, (off_t)dltotal); payload->handle->dlcb(payload->remote_name, 0, (off_t)dltotal);
} }
payload->handle->dlcb(payload->remote_name, current_size, total_size); payload->handle->dlcb(payload->remote_name, current_size, total_size);
prevprogress = current_size; payload->prevprogress = current_size;
return 0; return 0;
} }
@ -376,9 +374,6 @@ static int curl_download_internal(struct dload_payload *payload,
mask_signal(SIGPIPE, SIG_IGN, &orig_sig_pipe); mask_signal(SIGPIPE, SIG_IGN, &orig_sig_pipe);
mask_signal(SIGINT, &inthandler, &orig_sig_int); mask_signal(SIGINT, &inthandler, &orig_sig_int);
/* Progress 0 - initialize */
prevprogress = 0;
/* perform transfer */ /* perform transfer */
payload->curlerr = curl_easy_perform(curl); payload->curlerr = curl_easy_perform(curl);

View file

@ -35,6 +35,7 @@ struct dload_payload {
char *fileurl; char *fileurl;
off_t initial_size; off_t initial_size;
off_t max_size; off_t max_size;
off_t prevprogress;
int force; int force;
int allow_resume; int allow_resume;
int errors_ok; int errors_ok;