From 242e9e90f4190b9f770a0230e99d302f7ec53e70 Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Fri, 29 Aug 2008 17:24:34 +0200 Subject: Another attempt at fixing totaldownload. This fixes FS#11339, which 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 Signed-off-by: Dan McGee --- src/pacman/callback.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index a6349874..82dabae3 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) { @@ -438,6 +436,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; @@ -453,6 +452,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 { @@ -465,8 +470,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; @@ -503,7 +507,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; @@ -584,7 +588,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; } -- cgit v1.2.3-70-g09d2