[pacman-dev] [PATCH 1/2] Move download callback static vars into function
Signed-off-by: Dan McGee <dan@archlinux.org> --- src/pacman/callback.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 0d9b57b..793facd 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -37,11 +37,8 @@ #include "conf.h" /* download progress bar */ -static double rate_last; -static off_t xfered_last; static off_t list_xfered = 0.0; static off_t list_total = 0.0; -static struct timeval initial_time; /* delayed output during progress bar */ static int on_progress = 0; @@ -510,6 +507,9 @@ void cb_dl_total(off_t total) /* callback to handle display of download progress */ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) { + static double rate_last; + static off_t xfered_last; + static struct timeval initial_time; int infolen; int filenamelen; char *fname, *p; -- 1.7.6.1
Display now looks like this, whereas before we would have just showed '2M/s' for the extra repository download. The cutoff is placed at 100.0 to ensure we only use 4 character slots of width (e.g. '99.9', '100'). :: Synchronizing package databases... testing 39.9 KiB 470K/s 00:00 [######################] 100% core 51.4 KiB 469K/s 00:00 [######################] 100% extra 768.8 KiB 2.1M/s 00:00 [######################] 100% community-testing 1941.0 B 54.4M/s 00:00 [######################] 100% multilib 26.6 KiB 458K/s 00:00 [######################] 100% community 449.8 KiB 1649K/s 00:00 [######################] 100% Signed-off-by: Dan McGee <dan@archlinux.org> --- src/pacman/callback.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 793facd..7bed43c 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -688,8 +688,14 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) xfered_human = humanize_size(xfered, '\0', &xfered_label); printf(" %ls%-*s ", wcfname, padwid, ""); - printf("%6.1f %3s %4.f%c/s ", - xfered_human, xfered_label, rate_human, rate_label[0]); + /* We will show 1.6M/s, 11.6M/s, but 116K/s and 1116K/s */ + if(rate_human < 100.0) { + printf("%6.1f %3s %4.1f%c/s ", + xfered_human, xfered_label, rate_human, rate_label[0]); + } else { + printf("%6.1f %3s %4.f%c/s ", + xfered_human, xfered_label, rate_human, rate_label[0]); + } if(eta_h == 0) { printf("%02u:%02u", eta_m, eta_s); } else if(eta_h < 100) { -- 1.7.6.1
participants (1)
-
Dan McGee