diff options
Diffstat (limited to 'src/pacman/callback.c')
-rw-r--r-- | src/pacman/callback.c | 124 |
1 files changed, 75 insertions, 49 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index f5bf17d1..a80172b2 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -1,7 +1,7 @@ /* * callback.c * - * Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify @@ -26,7 +26,6 @@ #include <sys/time.h> #include <sys/types.h> /* off_t */ #include <unistd.h> -#include <dirent.h> #include <wchar.h> #include <alpm.h> @@ -37,7 +36,7 @@ #include "conf.h" /* download progress bar */ -static float rate_last; +static double rate_last; static off_t xfered_last; static off_t list_xfered = 0.0; static off_t list_total = 0.0; @@ -56,9 +55,9 @@ static alpm_list_t *output = NULL; * * first_call indicates if this is the first time it is called, for * initialization purposes */ -static float get_update_timediff(int first_call) +static double get_update_timediff(int first_call) { - float retval = 0.0; + double retval = 0.0; static struct timeval last_time = {0, 0}; /* on first call, simply set the last time and return */ @@ -66,7 +65,7 @@ static float get_update_timediff(int first_call) gettimeofday(&last_time, NULL); } else { struct timeval this_time; - float diff_sec, diff_usec; + double diff_sec, diff_usec; gettimeofday(&this_time, NULL); diff_sec = this_time.tv_sec - last_time.tv_sec; @@ -79,7 +78,6 @@ static float get_update_timediff(int first_call) retval = 0.0; } else { last_time = this_time; - /* printf("\nupdate retval: %f\n", retval); DEBUG*/ } } @@ -163,7 +161,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) break; case PM_TRANS_EVT_FILECONFLICTS_START: if(config->noprogressbar) { - printf(_("checking for file conflicts...\n")); + printf(_("checking for file conflicts...\n")); } break; case PM_TRANS_EVT_RESOLVEDEPS_START: @@ -206,7 +204,9 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) display_new_optdepends(data2,data1); break; case PM_TRANS_EVT_INTEGRITY_START: - printf(_("checking package integrity...\n")); + if(config->noprogressbar) { + printf(_("checking package integrity...\n")); + } break; case PM_TRANS_EVT_DELTA_INTEGRITY_START: printf(_("checking delta integrity...\n")); @@ -229,6 +229,11 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) case PM_TRANS_EVT_RETRIEVE_START: printf(_(":: Retrieving packages from %s...\n"), (char*)data1); break; + case PM_TRANS_EVT_DISKSPACE_START: + if(config->noprogressbar) { + printf(_("checking available disk space...\n")); + } + break; /* all the simple done events, with fallthrough for each */ case PM_TRANS_EVT_FILECONFLICTS_DONE: case PM_TRANS_EVT_CHECKDEPS_DONE: @@ -237,6 +242,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) case PM_TRANS_EVT_INTEGRITY_DONE: case PM_TRANS_EVT_DELTA_INTEGRITY_DONE: case PM_TRANS_EVT_DELTA_PATCHES_DONE: + case PM_TRANS_EVT_DISKSPACE_DONE: /* nothing */ break; } @@ -262,7 +268,7 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, case PM_TRANS_CONV_CONFLICT_PKG: /* data parameters: target package, local package, conflict (strings) */ /* print conflict only if it contains new information */ - if(!strcmp(data1, data3) || !strcmp(data2, data3)) { + if(strcmp(data1, data3) == 0 || strcmp(data2, data3) == 0) { *response = noyes(_(":: %s and %s are in conflict. Remove %s?"), (char *)data1, (char *)data2, @@ -279,18 +285,36 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, { alpm_list_t *unresolved = (alpm_list_t *) data1; alpm_list_t *namelist = NULL, *i; + size_t count = alpm_list_count(namelist); for (i = unresolved; i; i = i->next) { namelist = alpm_list_add(namelist, (char *)alpm_pkg_get_name(i->data)); } - printf(_(":: the following package(s) cannot be upgraded due to " - "unresolvable dependencies:\n")); + printf(_n( + ":: The following package cannot be upgraded due to unresolvable dependencies:\n", + ":: The following packages cannot be upgraded due to unresolvable dependencies:\n", + count)); list_display(" ", namelist); - *response = noyes(_("\nDo you want to skip the above " - "package(s) for this upgrade?")); + printf("\n"); + *response = noyes(_n( + "Do you want to skip the above package for this upgrade?", + "Do you want to skip the above packages for this upgrade?", + count)); alpm_list_free(namelist); } break; + case PM_TRANS_CONV_SELECT_PROVIDER: + { + alpm_list_t *providers = (alpm_list_t *)data1; + int count = alpm_list_count(providers); + char *depstring = alpm_dep_compute_string((pmdepend_t *)data2); + printf(_(":: There are %d providers available for %s:\n"), count, + depstring); + free(depstring); + select_display(providers); + *response = select_question(count); + } + break; case PM_TRANS_CONV_LOCAL_NEWER: if(!config->op_s_downloadonly) { *response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"), @@ -315,13 +339,12 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, /* callback to handle display of transaction progress */ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, - int howmany, int remain) + size_t howmany, size_t current) { - float timediff; - /* size of line to allocate for text printing (e.g. not progressbar) */ int infolen; - int tmp, digits, textlen; + int digits, textlen; + size_t tmp; char *opr = NULL; /* used for wide character width determination and printing */ int len, wclen, wcwid, padwid; @@ -331,32 +354,24 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, return; } - infolen = getcols() * 6 / 10; - if (infolen < 50) { - infolen = 50; - } - if(percent == 0) { - timediff = get_update_timediff(1); + get_update_timediff(1); + } else if(percent == 100) { + /* no need for timediff update, but unconditionally continue unless we + * already completed on a previous call */ + if(prevpercent == 100) { + return; + } } else { - timediff = get_update_timediff(0); - } - - if(percent > 0 && percent < 100 && !timediff) { - /* only update the progress bar when - * a) we first start - * b) we end the progress - * c) it has been long enough since the last call - */ - return; + 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. */ + return; + } } - /* if no pkgname, percent is too high or unchanged, then return */ - if(!pkgname || percent == prevpercent) { - return; - } + prevpercent = percent; - prevpercent=percent; /* set text of message to display */ switch (event) { case PM_TRANS_PROGRESS_ADD_START: @@ -371,10 +386,21 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, case PM_TRANS_PROGRESS_CONFLICTS_START: opr = _("checking for file conflicts"); break; + case PM_TRANS_PROGRESS_DISKSPACE_START: + opr = _("checking available disk space"); + break; + case PM_TRANS_PROGRESS_INTEGRITY_START: + opr = _("checking package integrity"); + break; default: return; } + infolen = getcols() * 6 / 10; + if (infolen < 50) { + infolen = 50; + } + /* find # of digits in package counts to scale output */ digits = 1; tmp = howmany; @@ -389,7 +415,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, * done here to figure out the actual number of screen columns used * by the output, and then pad it accordingly so we fill the terminal. */ - /* len = opr len + pkgname len (if available) + space + null */ + /* len = opr len + pkgname len (if available) + space + null */ len = strlen(opr) + ((pkgname) ? strlen(pkgname) : 0) + 2; wcstr = calloc(len, sizeof(wchar_t)); /* print our strings to the alloc'ed memory */ @@ -421,8 +447,8 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, } - printf("(%*d/%*d) %ls%-*s", digits, remain, digits, howmany, - wcstr, padwid, ""); + printf("(%*ld/%*ld) %ls%-*s", digits, (unsigned long)current, + digits, (unsigned long)howmany, wcstr, padwid, ""); free(wcstr); @@ -465,7 +491,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) int totaldownload = 0; off_t xfered, total; - float rate = 0.0, timediff = 0.0, f_xfered = 0.0; + double rate = 0.0, timediff = 0.0, f_xfered = 0.0; unsigned int eta_h = 0, eta_m = 0, eta_s = 0; int file_percent = 0, total_percent = 0; char rate_size = 'K', xfered_size = 'K'; @@ -524,7 +550,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) } else if(file_xfered == file_total) { /* compute final values */ struct timeval current_time; - float diff_sec, diff_usec; + double diff_sec, diff_usec; gettimeofday(¤t_time, NULL); diff_sec = current_time.tv_sec - initial_time.tv_sec; @@ -550,11 +576,11 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) xfered_last = xfered; } - file_percent = (int)((float)file_xfered) / ((float)file_total) * 100; + file_percent = (file_xfered * 100) / file_total; if(totaldownload) { - total_percent = (int)((float)list_xfered + file_xfered) / - ((float)list_total) * 100; + total_percent = ((list_xfered + file_xfered) * 100) / + list_total; /* if we are at the end, add the completed file to list_xfered */ if(file_xfered == file_total) { @@ -570,7 +596,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) fname = strdup(filename); /* strip package or DB extension for cleaner look */ - if((p = strstr(fname, ".pkg.tar.")) || (p = strstr(fname, ".db.tar."))) { + if((p = strstr(fname, ".pkg")) || (p = strstr(fname, ".db"))) { *p = '\0'; } /* In order to deal with characters from all locales, we have to worry @@ -643,7 +669,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) } /* Callback to handle notifications from the library */ -void cb_log(pmloglevel_t level, char *fmt, va_list args) +void cb_log(pmloglevel_t level, const char *fmt, va_list args) { if(!fmt || strlen(fmt) == 0) { return; |