pacman: check if pkgname is empty instead of null in progress

The progress callback always uses an empty string when there is no
pkgname. However pacman checks if the argument is null.

Check if the string is empty instead and better document what is passed
to the progress callback.
This commit is contained in:
morganamilo 2024-02-03 14:31:43 +00:00 committed by Allan McRae
parent 0649a66ee5
commit da4b590bce
2 changed files with 5 additions and 3 deletions

View file

@ -1149,7 +1149,9 @@ typedef enum _alpm_progress_t {
* make take a while to complete.
* @param ctx user-provided context
* @param progress the kind of event that is progressing
* @param pkg for package operations, the name of the package being operated on
* @param pkg the name of the package being operated on. if the progress kind
* is a packae operation (add, upgrade, downgrade, reinstall, remove).
* otherwise this will be an empty string.
* @param percent the percent completion of the action
* @param howmany the total amount of items in the action
* @param current the current amount of items completed

View file

@ -589,7 +589,7 @@ void cb_progress(void *ctx, alpm_progress_t event, const char *pkgname,
} else {
if(current != prevcurrent) {
/* update always */
} else if(!pkgname || percent == prevpercent ||
} else if(pkgname[0] == '\0' || percent == prevpercent ||
get_update_timediff(0) < UPDATE_SPEED_MS) {
/* only update the progress bar when we have a package name, the
* percentage has changed, and it has been long enough. */
@ -653,7 +653,7 @@ void cb_progress(void *ctx, alpm_progress_t event, const char *pkgname,
* by the output, and then pad it accordingly so we fill the terminal.
*/
/* len = opr len + pkgname len (if available) + space + null */
len = strlen(opr) + ((pkgname) ? strlen(pkgname) : 0) + 2;
len = strlen(opr) + strlen(pkgname) + 2;
wcstr = calloc(len, sizeof(wchar_t));
/* print our strings to the alloc'ed memory */
#if defined(HAVE_SWPRINTF)