[pacman-dev] [PATCH 1/5] libalpm: remove useless if
--- lib/libalpm/dload.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index d43e6d45..d3636e18 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -899,10 +899,6 @@ int SYMEXPORT alpm_fetch_pkgurl(alpm_handle_t *handle, const alpm_list_t *urls, struct dload_payload *payload = i->data; char *filepath; - if(payload->signature) { - continue; - } - if(payload->destfile_name) { const char *filename = mbasename(payload->destfile_name); filepath = _alpm_filecache_find(handle, filename); -- 2.30.0
The progress bar already did this. But the init event and up to date message allways printed the full file name, which doesn't match the progress bar. --- src/pacman/callback.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 9cc7541d..6ed7557a 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -749,18 +749,34 @@ static void init_total_progressbar(void) totalbar->rate = 0.0; } +static char *clean_filename(const char *filename) +{ + int len = strlen(filename); + char *p; + char *fname = malloc(len + 1); + memcpy(fname, filename, len + 1); + /* strip package or DB extension for cleaner look */ + if((p = strstr(fname, ".pkg")) || (p = strstr(fname, ".db")) || (p = strstr(fname, ".files"))) { + len = p - fname; + fname[len] = '\0'; + } + + return fname; +} + static void draw_pacman_progress_bar(struct pacman_progress_bar *bar) { int infolen; int filenamelen; - char *fname, *p; + char *fname; /* used for wide character width determination and printing */ - int len, wclen, wcwid, padwid; + int wclen, wcwid, padwid; wchar_t *wcfname; unsigned int eta_h = 0, eta_m = 0, eta_s = bar->eta; 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(); @@ -776,14 +792,8 @@ static void draw_pacman_progress_bar(struct pacman_progress_bar *bar) eta_m = eta_s / 60; eta_s -= eta_m * 60; - len = strlen(bar->filename); - fname = malloc(len + 1); - memcpy(fname, bar->filename, len + 1); - /* strip package or DB extension for cleaner look */ - if((p = strstr(fname, ".pkg")) || (p = strstr(fname, ".db")) || (p = strstr(fname, ".files"))) { - len = p - fname; - fname[len] = '\0'; - } + fname = clean_filename(bar->filename); + infolen = cols * 6 / 10; if(infolen < 50) { @@ -859,7 +869,9 @@ static void dload_init_event(const char *filename, alpm_download_event_init_t *d (void)data; if(!dload_progressbar_enabled()) { - printf(_(" %s downloading...\n"), filename); + char *cleaned_filename = clean_filename(filename); + printf(_(" %s downloading...\n"), cleaned_filename); + free(cleaned_filename); return; } @@ -992,7 +1004,9 @@ static void dload_complete_event(const char *filename, alpm_download_event_compl if(data->result == 1) { console_cursor_goto_bar(index); - printf(_(" %s is up to date"), bar->filename); + char *cleaned_filename = clean_filename(filename); + printf(_(" %s is up to date"), cleaned_filename); + free(cleaned_filename); /* The line contains text from previous status. Erase these leftovers. */ console_erase_line(); } else if(data->result == 0) { -- 2.30.0
--- lib/libalpm/dload.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index d3636e18..df5e8be7 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -391,7 +391,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, CURLcode curlerr; char *effective_url; long timecond; - double remote_size, bytes_dl = 0; + curl_off_t remote_size; + curl_off_t bytes_dl = 0; long remote_time = -1; struct stat st; char hostname[HOSTNAME_SIZE]; @@ -476,8 +477,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* retrieve info about the state of the transfer */ curl_easy_getinfo(curl, CURLINFO_FILETIME, &remote_time); - curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &remote_size); - curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &bytes_dl); + curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &remote_size); + curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &bytes_dl); curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &timecond); curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url); @@ -539,7 +540,7 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* time condition was met and we didn't download anything. we need to * clean up the 0 byte .part file that's left behind. */ - if(timecond == 1 && DOUBLE_EQ(bytes_dl, 0)) { + if(timecond == 1 && bytes_dl == 0) { _alpm_log(handle, ALPM_LOG_DEBUG, "%s: file met time condition\n", payload->remote_name); ret = 1; @@ -550,8 +551,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* remote_size isn't necessarily the full size of the file, just what the * server reported as remaining to download. compare it to what curl reported * as actually being transferred during curl_easy_perform() */ - if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) && - !DOUBLE_EQ(bytes_dl, remote_size)) { + if(remote_size != -1 && bytes_dl != -1 && + bytes_dl != remote_size) { _alpm_log(handle, ALPM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"), payload->remote_name, (intmax_t)bytes_dl, (intmax_t)remote_size); GOTO_ERR(handle, ALPM_ERR_RETRIEVE, cleanup); -- 2.30.0
On 1/1/21 11:57 AM, morganamilo via pacman-dev wrote:
--- lib/libalpm/dload.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index d3636e18..df5e8be7 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -391,7 +391,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, CURLcode curlerr; char *effective_url; long timecond; - double remote_size, bytes_dl = 0; + curl_off_t remote_size; + curl_off_t bytes_dl = 0; long remote_time = -1; struct stat st; char hostname[HOSTNAME_SIZE]; @@ -476,8 +477,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg,
/* retrieve info about the state of the transfer */ curl_easy_getinfo(curl, CURLINFO_FILETIME, &remote_time); - curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &remote_size); - curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &bytes_dl);
Originally implemented in dload.c in commit 96e458b705eda4ddff7d6ec890cf1daf898e9186 in 2011.
+ curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &remote_size); + curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &bytes_dl);
AVAILABILITY Added in 7.55.0 A change like this MUST bump the minimum required dependency version. Admittedly a version from mid-2017 is not hard to get, but on the other hand, it's not really deprecated... just an older style. I don't have a strong opinion on whether or not to do all this. But please resubmit with changes to meson.build too.
curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &timecond); curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url);
@@ -539,7 +540,7 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg,
/* time condition was met and we didn't download anything. we need to * clean up the 0 byte .part file that's left behind. */ - if(timecond == 1 && DOUBLE_EQ(bytes_dl, 0)) { + if(timecond == 1 && bytes_dl == 0) { _alpm_log(handle, ALPM_LOG_DEBUG, "%s: file met time condition\n", payload->remote_name); ret = 1; @@ -550,8 +551,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* remote_size isn't necessarily the full size of the file, just what the * server reported as remaining to download. compare it to what curl reported * as actually being transferred during curl_easy_perform() */ - if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) && - !DOUBLE_EQ(bytes_dl, remote_size)) { + if(remote_size != -1 && bytes_dl != -1 && + bytes_dl != remote_size) {
Given you're removing all users of the util.h DOUBLE_EQ macro, you could be dropping the macro at the same time.
_alpm_log(handle, ALPM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"), payload->remote_name, (intmax_t)bytes_dl, (intmax_t)remote_size); GOTO_ERR(handle, ALPM_ERR_RETRIEVE, cleanup);
-- Eli Schwartz Bug Wrangler and Trusted User
On 1/1/21 1:57 PM, Eli Schwartz wrote:
On 1/1/21 11:57 AM, morganamilo via pacman-dev wrote:
--- lib/libalpm/dload.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index d3636e18..df5e8be7 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -391,7 +391,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, CURLcode curlerr; char *effective_url; long timecond; - double remote_size, bytes_dl = 0; + curl_off_t remote_size; + curl_off_t bytes_dl = 0; long remote_time = -1; struct stat st; char hostname[HOSTNAME_SIZE]; @@ -476,8 +477,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* retrieve info about the state of the transfer */ curl_easy_getinfo(curl, CURLINFO_FILETIME, &remote_time); - curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &remote_size); - curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &bytes_dl);
Originally implemented in dload.c in commit 96e458b705eda4ddff7d6ec890cf1daf898e9186 in 2011.
+ curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &remote_size); + curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &bytes_dl);
AVAILABILITY
Added in 7.55.0
A change like this MUST bump the minimum required dependency version. Admittedly a version from mid-2017 is not hard to get, but on the other hand, it's not really deprecated... just an older style.
Apparently it is deprecated on https://curl.se/libcurl/c/curl_easy_getinfo.html But not on https://curl.se/libcurl/c/CURLINFO_CONTENT_LENGTH_DOWNLOAD.html Sorry...
I don't have a strong opinion on whether or not to do all this. But please resubmit with changes to meson.build too.
curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &timecond); curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url); @@ -539,7 +540,7 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* time condition was met and we didn't download anything. we need to * clean up the 0 byte .part file that's left behind. */ - if(timecond == 1 && DOUBLE_EQ(bytes_dl, 0)) { + if(timecond == 1 && bytes_dl == 0) { _alpm_log(handle, ALPM_LOG_DEBUG, "%s: file met time condition\n", payload->remote_name); ret = 1; @@ -550,8 +551,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* remote_size isn't necessarily the full size of the file, just what the * server reported as remaining to download. compare it to what curl reported * as actually being transferred during curl_easy_perform() */ - if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) && - !DOUBLE_EQ(bytes_dl, remote_size)) { + if(remote_size != -1 && bytes_dl != -1 && + bytes_dl != remote_size) {
Given you're removing all users of the util.h DOUBLE_EQ macro, you could be dropping the macro at the same time.
_alpm_log(handle, ALPM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"), payload->remote_name, (intmax_t)bytes_dl, (intmax_t)remote_size); GOTO_ERR(handle, ALPM_ERR_RETRIEVE, cleanup);
-- Eli Schwartz Bug Wrangler and Trusted User
This bumps the minimun curl version from 7.32.0 to 7.55.0. --- lib/libalpm/dload.c | 13 +++++++------ lib/libalpm/util.h | 2 -- meson.build | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index d3636e18..df5e8be7 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -391,7 +391,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, CURLcode curlerr; char *effective_url; long timecond; - double remote_size, bytes_dl = 0; + curl_off_t remote_size; + curl_off_t bytes_dl = 0; long remote_time = -1; struct stat st; char hostname[HOSTNAME_SIZE]; @@ -476,8 +477,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* retrieve info about the state of the transfer */ curl_easy_getinfo(curl, CURLINFO_FILETIME, &remote_time); - curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &remote_size); - curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &bytes_dl); + curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &remote_size); + curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &bytes_dl); curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &timecond); curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url); @@ -539,7 +540,7 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* time condition was met and we didn't download anything. we need to * clean up the 0 byte .part file that's left behind. */ - if(timecond == 1 && DOUBLE_EQ(bytes_dl, 0)) { + if(timecond == 1 && bytes_dl == 0) { _alpm_log(handle, ALPM_LOG_DEBUG, "%s: file met time condition\n", payload->remote_name); ret = 1; @@ -550,8 +551,8 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, /* remote_size isn't necessarily the full size of the file, just what the * server reported as remaining to download. compare it to what curl reported * as actually being transferred during curl_easy_perform() */ - if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) && - !DOUBLE_EQ(bytes_dl, remote_size)) { + if(remote_size != -1 && bytes_dl != -1 && + bytes_dl != remote_size) { _alpm_log(handle, ALPM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"), payload->remote_name, (intmax_t)bytes_dl, (intmax_t)remote_size); GOTO_ERR(handle, ALPM_ERR_RETRIEVE, cleanup); diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 03c8ed44..2f120adc 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -81,8 +81,6 @@ void _alpm_alloc_fail(size_t size); (handle)->pm_errno = (err); \ return (ret); } while(0) -#define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON) - #define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } (handle)->pm_errno = ALPM_ERR_OK; } while(0) /** Standard buffer size used throughout the library. */ diff --git a/meson.build b/meson.build index 264c6501..2002dc78 100644 --- a/meson.build +++ b/meson.build @@ -94,7 +94,7 @@ libarchive = dependency('libarchive', static : get_option('buildstatic')) libcurl = dependency('libcurl', - version : '>=7.32.0', + version : '>=7.55.0', required : get_option('curl'), static : get_option('buildstatic')) conf.set('HAVE_LIBCURL', libcurl.found()) -- 2.30.0
--- lib/libalpm/alpm.h | 3 ++- lib/libalpm/sync.c | 6 +++++- src/pacman/callback.c | 3 ++- src/pacman/callback.h | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 72c4fb24..92586043 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -1189,9 +1189,10 @@ typedef void (*alpm_cb_download)(const char *filename, /** Total Download callback. + * @param howmany the number of packages that will be downloaded during \link alpm_trans_commit \endlink. * @param total amount that will be downloaded during \link alpm_trans_commit \endlink. */ -typedef void (*alpm_cb_totaldl)(off_t total); +typedef void (*alpm_cb_totaldl)(size_t howmany, off_t total); /** A callback for downloading files * @param url the URL of the file to be downloaded diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index e25e56d4..3919d266 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -760,12 +760,16 @@ static int download_files(alpm_handle_t *handle) * frontend to compute incremental progress. */ if(handle->totaldlcb) { off_t total_size = (off_t)0; + size_t howmany = 0; /* sum up the download size for each package and store total */ for(i = handle->trans->add; i; i = i->next) { alpm_pkg_t *spkg = i->data; total_size += spkg->download_size; + if(spkg->download_size > 0) { + howmany++; + } } - handle->totaldlcb(total_size); + handle->totaldlcb(howmany, total_size); } ret = find_dl_candidates(handle, &files); diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 6ed7557a..f11382a0 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -694,8 +694,9 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent, } /* callback to handle receipt of total download value */ -void cb_dl_total(off_t total) +void cb_dl_total(size_t howmany, off_t total) { + (void)howmany; list_total = total; } diff --git a/src/pacman/callback.h b/src/pacman/callback.h index 09d544a6..508c96b3 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -36,7 +36,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent, size_t howmany, size_t remain); /* callback to handle receipt of total download value */ -void cb_dl_total(off_t total); +void cb_dl_total(size_t howmany, off_t total); /* callback to handle display of download progress */ void cb_download(const char *filename, alpm_download_event_type_t event, void *data); -- 2.30.0
On 2/1/21 2:57 am, morganamilo via pacman-dev wrote:
--- lib/libalpm/alpm.h | 3 ++- lib/libalpm/sync.c | 6 +++++- src/pacman/callback.c | 3 ++- src/pacman/callback.h | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-)
ok - changed the commit message slightly, as it confused me! libalpm: pass the number of packages being downloaded in totaldlcb
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 72c4fb24..92586043 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -1189,9 +1189,10 @@ typedef void (*alpm_cb_download)(const char *filename,
/** Total Download callback. + * @param howmany the number of packages that will be downloaded during \link alpm_trans_commit \endlink. * @param total amount that will be downloaded during \link alpm_trans_commit \endlink. */ -typedef void (*alpm_cb_totaldl)(off_t total); +typedef void (*alpm_cb_totaldl)(size_t howmany, off_t total);
/** A callback for downloading files * @param url the URL of the file to be downloaded diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index e25e56d4..3919d266 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -760,12 +760,16 @@ static int download_files(alpm_handle_t *handle) * frontend to compute incremental progress. */ if(handle->totaldlcb) { off_t total_size = (off_t)0; + size_t howmany = 0; /* sum up the download size for each package and store total */ for(i = handle->trans->add; i; i = i->next) { alpm_pkg_t *spkg = i->data; total_size += spkg->download_size; + if(spkg->download_size > 0) { + howmany++; + } } - handle->totaldlcb(total_size); + handle->totaldlcb(howmany, total_size); }
ret = find_dl_candidates(handle, &files); diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 6ed7557a..f11382a0 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -694,8 +694,9 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent, }
/* callback to handle receipt of total download value */ -void cb_dl_total(off_t total) +void cb_dl_total(size_t howmany, off_t total) { + (void)howmany; list_total = total; }
diff --git a/src/pacman/callback.h b/src/pacman/callback.h index 09d544a6..508c96b3 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -36,7 +36,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent, size_t howmany, size_t remain);
/* callback to handle receipt of total download value */ -void cb_dl_total(off_t total); +void cb_dl_total(size_t howmany, off_t total); /* callback to handle display of download progress */ void cb_download(const char *filename, alpm_download_event_type_t event, void *data);
--- 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); + 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; -- 2.30.0
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;
On 2/1/21 2:57 am, morganamilo via pacman-dev wrote:
--- lib/libalpm/dload.c | 4 ---- 1 file changed, 4 deletions(-)
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index d43e6d45..d3636e18 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -899,10 +899,6 @@ int SYMEXPORT alpm_fetch_pkgurl(alpm_handle_t *handle, const alpm_list_t *urls, struct dload_payload *payload = i->data; char *filepath;
- if(payload->signature) { - continue; - } -
Trying to figure out why this was here. Looks fine to remove.
if(payload->destfile_name) { const char *filename = mbasename(payload->destfile_name); filepath = _alpm_filecache_find(handle, filename);
participants (3)
-
Allan McRae
-
Eli Schwartz
-
morganamilo