[pacman-dev] [PATCH 1/2] Ensure progress callback updates if XX/YY numerator changes
We only updated if the percentage incremented and enough time had elapsed, even though the numerator of the current/howmany fraction may have changed. Ensure we proceed with the progress bar update in these cases so as to not mislead the user. Signed-off-by: Dan McGee <dan@archlinux.org> --- src/pacman/callback.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 04b3a52..e832b49 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -43,9 +43,6 @@ static off_t list_xfered = 0.0; static off_t list_total = 0.0; static struct timeval initial_time; -/* transaction progress bar */ -static int prevpercent = 0; /* for less progressbar output */ - /* delayed output during progress bar */ static int on_progress = 0; static alpm_list_t *output = NULL; @@ -349,6 +346,8 @@ void cb_trans_conv(alpm_transconv_t event, void *data1, void *data2, void cb_trans_progress(alpm_transprog_t event, const char *pkgname, int percent, size_t howmany, size_t current) { + static int prevpercent; + static size_t prevcurrent; /* size of line to allocate for text printing (e.g. not progressbar) */ int infolen; int digits, textlen; @@ -373,14 +372,18 @@ void cb_trans_progress(alpm_transprog_t event, const char *pkgname, int percent, return; } } else { - if(!pkgname || percent == prevpercent || get_update_timediff(0) < UPDATE_SPEED_SEC) { + if(current != prevcurrent) { + /* update always */ + } else if(!pkgname || percent == prevpercent || + get_update_timediff(0) < UPDATE_SPEED_SEC) { /* only update the progress bar when we have a package name, the - * percentage has changed, and it has been long enough. */ + * percentage has changed, and it has been long enough. */ return; } } prevpercent = percent; + prevcurrent = current; /* set text of message to display */ switch (event) { -- 1.7.6.1
This upgrades the simple 15/17 scaling by package number we used before to package sized based scaling, which is much more accurate. Addresses some of the issues raised in FS#25817. Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/sync.c | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 19038b4..023ad62 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -894,7 +894,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) { alpm_list_t *i; alpm_list_t *deltas = NULL; - size_t numtargs, current = 0, replaces = 0; + size_t numtargs, current, replaces = 0; + size_t current_bytes, total_bytes; int errors; alpm_trans_t *trans = handle->trans; @@ -909,18 +910,31 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) } alpm_list_free(deltas); + /* get the total size of all packages so we can adjust the progress bar more + * realistically if there are small and huge packages involved */ + current = total_bytes = 0; + for(i = trans->add; i; i = i->next, current++) { + alpm_pkg_t *spkg = i->data; + if(spkg->origin != PKG_FROM_FILE) { + total_bytes += alpm_pkg_get_size(spkg); + } + } + /* this can only happen maliciously */ + total_bytes = total_bytes ? total_bytes : 1; + /* Check integrity of packages */ numtargs = alpm_list_count(trans->add); EVENT(trans, ALPM_TRANS_EVT_INTEGRITY_START, NULL, NULL); + current = current_bytes = 0; errors = 0; for(i = trans->add; i; i = i->next, current++) { alpm_pkg_t *spkg = i->data; - int percent = (current * 100) / numtargs; const char *filename; char *filepath; alpm_siglevel_t level; + int percent = (int)(((double)current_bytes / total_bytes) * 100); PROGRESS(trans, ALPM_TRANS_PROGRESS_INTEGRITY_START, "", percent, numtargs, current); @@ -928,6 +942,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data) continue; /* pkg_load() has been already called, this package is valid */ } + current_bytes += alpm_pkg_get_size(spkg); filename = alpm_pkg_get_filename(spkg); filepath = _alpm_filecache_find(handle, filename); alpm_db_t *sdb = alpm_pkg_get_db(spkg); -- 1.7.6.1
participants (1)
-
Dan McGee