From 58140dba7440997e9d318fb56ed939a9c81fddf8 Mon Sep 17 00:00:00 2001 From: Ivy Foster Date: Fri, 8 Jul 2016 22:11:25 -0500 Subject: Normalize alpm download callback's frontend cb arguments When curl calls alpm's dlcb, alpm calls the frontend's cb with the following (dlsize, totalsize) arguments: 0, -1: initialize 0, 0: no change since last call x {x>0, x0}: data downloaded, total size known x {x>0}, x: download finished If total size is not known, do not call frontend cb (no change to original behavior); alpm's callback shouldn't be called if there is a download error. See agregory's original spec here: https://wiki.archlinux.org/index.php/User:Apg#download_callback Signed-off-by: Allan McRae --- lib/libalpm/dload.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 31ae82c5..f4e6a278 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -126,14 +126,24 @@ static int dload_progress_cb(void *file, double dltotal, double dlnow, } /* 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); - } - + * a repo is up to date and nothing gets downloaded. + * payload->handle->dlcb will receive the remote_name + * and the following arguments: + * 0, -1: download initialized + * 0, 0: non-download event + * x {x>0}, x: download complete + * x {x>0, x 0}: download progress, expected total is known */ + if(current_size == total_size) { + payload->handle->dlcb(payload->remote_name, (off_t)dlnow, (off_t)dltotal); + } else if(!payload->prevprogress) { + payload->handle->dlcb(payload->remote_name, 0, -1); + } else if(payload->prevprogress == current_size) { + payload->handle->dlcb(payload->remote_name, 0, 0); + } else { /* do NOT include initial_size since it wasn't part of the 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, (off_t)dlnow, (off_t)dltotal); + } payload->prevprogress = current_size; -- cgit v1.2.3-70-g09d2