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 --- src/pacman/callback.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/pacman/callback.c b/src/pacman/callback.c index ab3e14f2..7f72b84f 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -678,8 +678,13 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) const unsigned short cols = getcols(); - if(config->noprogressbar || cols == 0 || file_total == -1) { - if(file_xfered == 0) { + /* Nothing has changed since last callback; stop here */ + if(file_xfered == 0 && file_total == 0) { + return; + } + + if(config->noprogressbar || cols == 0) { + if(file_xfered == 0 && file_total == -1) { printf(_("downloading %s...\n"), filename); fflush(stdout); } @@ -710,14 +715,9 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) total = file_total; } - /* bogus values : stop here */ - if(xfered > total || xfered < 0) { - return; - } - /* this is basically a switch on xfered: 0, total, and * anything else */ - if(file_xfered == 0) { + if(file_xfered == 0 && file_total == -1) { /* set default starting values, ensure we only call this once * if TotalDownload is enabled */ if(!totaldownload || (totaldownload && list_xfered == 0)) { @@ -726,6 +726,9 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) rate_last = 0.0; get_update_timediff(1); } + } else if(xfered > total || xfered < 0) { + /* bogus values : stop here */ + return; } else if(file_xfered == file_total) { /* compute final values */ int64_t timediff = get_time_ms() - initial_time; -- cgit v1.2.3-24-g4f1b