[pacman-dev] [PATCH 5/5] pacman: total download show how many packages have been download
Allan McRae
allan at archlinux.org
Fri Jan 8 04:12:41 UTC 2021
On 2/1/21 2:57 am, morganamilo via pacman-dev wrote:
> ---
> src/pacman/callback.c | 25 +++++++++++++++++++++----
> 1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/src/pacman/callback.c b/src/pacman/callback.c
> index f11382a0..b4c8bf00 100644
> --- a/src/pacman/callback.c
> +++ b/src/pacman/callback.c
> @@ -42,6 +42,7 @@
> /* download progress bar */
> static int total_enabled = 0;
> static off_t list_total = 0.0;
> +static size_t list_total_pkgs = 0;
> static struct pacman_progress_bar *totalbar;
>
> /* delayed output during progress bar */
> @@ -59,6 +60,8 @@ struct pacman_progress_bar {
> const char *filename;
> off_t xfered; /* Current amount of transferred data */
> off_t total_size;
> + size_t downloaded;
> + size_t howmany;
> uint64_t init_time; /* Time when this download started doing any progress */
> uint64_t sync_time; /* Last time we updated the bar info */
> off_t sync_xfered; /* Amount of transferred data at the `sync_time` timestamp. It can be
> @@ -696,7 +699,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
> /* callback to handle receipt of total download value */
> void cb_dl_total(size_t howmany, off_t total)
> {
> - (void)howmany;
> + list_total_pkgs = howmany;
> list_total = total;
> }
>
> @@ -744,9 +747,10 @@ static void init_total_progressbar(void)
> {
> totalbar = calloc(1, sizeof(struct pacman_progress_bar));
> assert(totalbar);
> - totalbar->filename = _("Total:");
> + totalbar->filename = _("Total");
> totalbar->init_time = get_time_ms();
> totalbar->total_size = list_total;
> + totalbar->howmany = list_total_pkgs;
> totalbar->rate = 0.0;
> }
>
> @@ -767,7 +771,7 @@ static char *clean_filename(const char *filename)
>
> static void draw_pacman_progress_bar(struct pacman_progress_bar *bar)
> {
> - int infolen;
> + int infolen, len;
> int filenamelen;
> char *fname;
> /* used for wide character width determination and printing */
> @@ -777,7 +781,6 @@ static void draw_pacman_progress_bar(struct pacman_progress_bar *bar)
> double rate_human, xfered_human;
> const char *rate_label, *xfered_label;
> int file_percent = 0;
> - int len = strlen(bar->filename);
>
> const unsigned short cols = getcols();
>
> @@ -795,7 +798,17 @@ static void draw_pacman_progress_bar(struct pacman_progress_bar *bar)
>
> fname = clean_filename(bar->filename);
>
> + if(bar->howmany > 0) {
> + int digits = number_length(bar->howmany);
> + // fname + digits + ( /) + \0
> + size_t needed = strlen(fname) + (digits * 2) + 4 + 1;
> + char *name = malloc(needed);
> + sprintf(name, "%s (%*zu/%*zu)", fname, digits, bar->downloaded, digits, bar->howmany);
../src/pacman/callback.c: In function ‘draw_pacman_progress_bar’:
../src/pacman/callback.c:806:27: error: ‘%*zu’ directive output between
1 and 2147483647 bytes may cause result to exceed ‘INT_MAX’
[-Werror=format-overflow=]
806 | sprintf(name, "%s (%*zu/%*zu)", fname, digits,
bar->downloaded, digits, bar->howmany);
| ^~~~
../src/pacman/callback.c:806:17: note: directive argument in the range
[1, 18446744073709551615]
806 | sprintf(name, "%s (%*zu/%*zu)", fname, digits,
bar->downloaded, digits, bar->howmany);
| ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
> + free(fname);
> + fname = name;
> + }
>
> + len = strlen(fname);
> infolen = cols * 6 / 10;
> if(infolen < 50) {
> infolen = 50;
> @@ -995,6 +1008,10 @@ static void dload_complete_event(const char *filename, alpm_download_event_compl
> return;
> }
>
> + if(total_enabled) {
> + totalbar->downloaded++;
> + }
> +
> ok = find_bar_for_filename(filename, &index, &bar);
> assert(ok);
> bar->completed = true;
>
More information about the pacman-dev
mailing list