[pacman-dev] [PATCH 1/3] dload_progress_cb: cast values to off_t up front
We only ever use them as off_t, so do the conversion early and avoid the
need for multiple casts and DOUBLE_EQ.
Signed-off-by: Andrew Gregory
Move the final call outside of curl's progress callback so that we can
notify our callback of completion even if the download size was unknown
or we encounter an error. Forces download total >= 0 within the
callback so that it can be used to indicate a download error.
Signed-off-by: Andrew Gregory
Previously the download progress callback would never be called if
servers failed to set Content-Length, preventing any output from being
shown to the user even though the download was still successfully
performed. Instead, show an indeterminate progress bar until the
download is complete, at which point it will be filled in.
Signed-off-by: Andrew Gregory
On Jan 25, 2015 12:25 PM, "Andrew Gregory"
We only ever use them as off_t, so do the conversion early and avoid the need for multiple casts and DOUBLE_EQ.
Signed-off-by: Andrew Gregory
--- lib/libalpm/dload.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index c5186be..cae4b7c 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -94,7 +94,7 @@ static int dload_progress_cb(void *file, double
I'd rather we use the newer XFERINFOFUNCTION (might have the name wrong) which passes these as curl_off_t instead of double. dltotal, double dlnow,
double UNUSED ultotal, double UNUSED ulnow) { struct dload_payload *payload = (struct dload_payload *)file; - off_t current_size, total_size; + off_t current_size, total_size, xfer = dlnow, total = dltotal;
/* avoid displaying progress bar for redirects with a body */ if(payload->respcode >= 300) { @@ -106,7 +106,7 @@ static int dload_progress_cb(void *file, double
dltotal, double dlnow,
return 1; }
- current_size = payload->initial_size + (off_t)dlnow; + current_size = payload->initial_size + xfer;
/* is our filesize still under any set limit? */ if(payload->max_size && current_size > payload->max_size) { @@ -119,21 +119,21 @@ static int dload_progress_cb(void *file, double
dltotal, double dlnow,
return 0; }
- total_size = payload->initial_size + (off_t)dltotal; + total_size = payload->initial_size + total;
- if(DOUBLE_EQ(dltotal, 0.0) || payload->prevprogress ==
+ if(total == 0 || payload->prevprogress == total_size) { return 0; }
/* initialize the progress bar here to avoid displaying it when * a repo is up to date and nothing gets downloaded */ if(payload->prevprogress == 0) { - payload->handle->dlcb(payload->remote_name, 0, (off_t)dltotal); + payload->handle->dlcb(payload->remote_name, 0, total); }
/* do NOT include initial_size since it wasn't part of the
total_size) { package's
* download_size (nor included in the total download size
callback) */
- payload->handle->dlcb(payload->remote_name, (off_t)dlnow, (off_t)dltotal); + payload->handle->dlcb(payload->remote_name, xfer, total);
payload->prevprogress = current_size;
-- 2.2.1
participants (2)
-
Andrew Gregory
-
Dave Reisner