From bdca9f9ab971adafbbd4205d8e18ebfb91d9ba0a Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Fri, 29 Aug 2008 17:24:34 +0200 Subject: [PATCH] Another attempt at fixing totaldownload. This is a regression of commit 89c2c5196 : When totaldownload is enabled, the database downloading percent (-Sy) is always at 0. That is because we have no guarantee that the totaldownload callback was called by libalpm. In particular, it is not called (and it would not make sense to) when a single file is downloaded, like it is the case with databases. So the correct way to detect if totaldownload should be used is checking both config->totaldownload and list_total, like it was already done in several places in the cb_dl_progress function. Signed-off-by: Xavier Chantry --- src/pacman/callback.c | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 59b4064..92a31f1 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -137,11 +137,9 @@ static void fill_progress(const int bar_percent, const int disp_percent, } printf("]"); } - /* print percent after progress bar */ + /* print display percent after progress bar */ if(proglen > 5) { - /* show total download percent if option is enabled */ - int p = config->totaldownload ? disp_percent : bar_percent; - printf(" %3d%%", p); + printf(" %3d%%", disp_percent); } if(bar_percent == 100) { @@ -435,6 +433,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) int len, wclen, wcwid, padwid; wchar_t *wcfname; + int totaldownload; off_t xfered, total; float rate = 0.0, timediff = 0.0, f_xfered = 0.0; unsigned int eta_h = 0, eta_m = 0, eta_s = 0; @@ -450,6 +449,12 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) /* only use TotalDownload if enabled and we have a callback value */ if(config->totaldownload && list_total) { + totaldownload = 1; + } else { + totaldownload = 0; + } + + if(totaldownload) { xfered = list_xfered + file_xfered; total = list_total; } else { @@ -462,8 +467,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) if(file_xfered == 0) { /* set default starting values, ensure we only call this once * if TotalDownload is enabled */ - if(!(config->totaldownload) - || (config->totaldownload && list_xfered == 0)) { + if(!totaldownload || (totaldownload && list_xfered == 0)) { gettimeofday(&initial_time, NULL); xfered_last = (off_t)0; rate_last = 0.0; @@ -500,7 +504,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) file_percent = (int)((float)file_xfered) / ((float)file_total) * 100; - if(config->totaldownload && list_total) { + if(totaldownload) { total_percent = (int)((float)list_xfered + file_xfered) / ((float)list_total) * 100; @@ -581,7 +585,11 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) free(fname); free(wcfname); - fill_progress(file_percent, total_percent, getcols() - infolen); + if(totaldownload) { + fill_progress(file_percent, total_percent, getcols() - infolen); + } else { + fill_progress(file_percent, file_percent, getcols() - infolen); + } return; } -- 1.6.0.1