diff options
Diffstat (limited to 'src/pacman/callback.c')
-rw-r--r-- | src/pacman/callback.c | 190 |
1 files changed, 90 insertions, 100 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 68672b4f..873e3fc9 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -82,7 +82,7 @@ static double get_update_timediff(int first_call) } } - return(retval); + return retval; } /* refactored from cb_trans_progress */ @@ -154,96 +154,96 @@ static void fill_progress(const int bar_percent, const int disp_percent, /* callback to handle messages/notifications from libalpm transactions */ -void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) +void cb_trans_evt(alpm_transevt_t event, void *data1, void *data2) { switch(event) { - case PM_TRANS_EVT_CHECKDEPS_START: + case ALPM_TRANS_EVT_CHECKDEPS_START: printf(_("checking dependencies...\n")); break; - case PM_TRANS_EVT_FILECONFLICTS_START: + case ALPM_TRANS_EVT_FILECONFLICTS_START: if(config->noprogressbar) { printf(_("checking for file conflicts...\n")); } break; - case PM_TRANS_EVT_RESOLVEDEPS_START: + case ALPM_TRANS_EVT_RESOLVEDEPS_START: printf(_("resolving dependencies...\n")); break; - case PM_TRANS_EVT_INTERCONFLICTS_START: + case ALPM_TRANS_EVT_INTERCONFLICTS_START: printf(_("looking for inter-conflicts...\n")); break; - case PM_TRANS_EVT_ADD_START: + case ALPM_TRANS_EVT_ADD_START: if(config->noprogressbar) { printf(_("installing %s...\n"), alpm_pkg_get_name(data1)); } break; - case PM_TRANS_EVT_ADD_DONE: - alpm_logaction("installed %s (%s)\n", + case ALPM_TRANS_EVT_ADD_DONE: + alpm_logaction(config->handle, "installed %s (%s)\n", alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); display_optdepends(data1); break; - case PM_TRANS_EVT_REMOVE_START: + case ALPM_TRANS_EVT_REMOVE_START: if(config->noprogressbar) { printf(_("removing %s...\n"), alpm_pkg_get_name(data1)); } break; - case PM_TRANS_EVT_REMOVE_DONE: - alpm_logaction("removed %s (%s)\n", + case ALPM_TRANS_EVT_REMOVE_DONE: + alpm_logaction(config->handle, "removed %s (%s)\n", alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); break; - case PM_TRANS_EVT_UPGRADE_START: + case ALPM_TRANS_EVT_UPGRADE_START: if(config->noprogressbar) { printf(_("upgrading %s...\n"), alpm_pkg_get_name(data1)); } break; - case PM_TRANS_EVT_UPGRADE_DONE: - alpm_logaction("upgraded %s (%s -> %s)\n", + case ALPM_TRANS_EVT_UPGRADE_DONE: + alpm_logaction(config->handle, "upgraded %s (%s -> %s)\n", (char *)alpm_pkg_get_name(data1), (char *)alpm_pkg_get_version(data2), (char *)alpm_pkg_get_version(data1)); display_new_optdepends(data2,data1); break; - case PM_TRANS_EVT_INTEGRITY_START: + case ALPM_TRANS_EVT_INTEGRITY_START: if(config->noprogressbar) { printf(_("checking package integrity...\n")); } break; - case PM_TRANS_EVT_DELTA_INTEGRITY_START: + case ALPM_TRANS_EVT_DELTA_INTEGRITY_START: printf(_("checking delta integrity...\n")); break; - case PM_TRANS_EVT_DELTA_PATCHES_START: + case ALPM_TRANS_EVT_DELTA_PATCHES_START: printf(_("applying deltas...\n")); break; - case PM_TRANS_EVT_DELTA_PATCH_START: + case ALPM_TRANS_EVT_DELTA_PATCH_START: printf(_("generating %s with %s... "), (char *)data1, (char *)data2); break; - case PM_TRANS_EVT_DELTA_PATCH_DONE: + case ALPM_TRANS_EVT_DELTA_PATCH_DONE: printf(_("success!\n")); break; - case PM_TRANS_EVT_DELTA_PATCH_FAILED: + case ALPM_TRANS_EVT_DELTA_PATCH_FAILED: printf(_("failed.\n")); break; - case PM_TRANS_EVT_SCRIPTLET_INFO: - printf("%s", (char*)data1); + case ALPM_TRANS_EVT_SCRIPTLET_INFO: + printf("%s", (char *)data1); break; - case PM_TRANS_EVT_RETRIEVE_START: - printf(_(":: Retrieving packages from %s...\n"), (char*)data1); + case ALPM_TRANS_EVT_RETRIEVE_START: + printf(_(":: Retrieving packages from %s...\n"), (char *)data1); break; - case PM_TRANS_EVT_DISKSPACE_START: + case ALPM_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: - case PM_TRANS_EVT_RESOLVEDEPS_DONE: - case PM_TRANS_EVT_INTERCONFLICTS_DONE: - 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: + case ALPM_TRANS_EVT_FILECONFLICTS_DONE: + case ALPM_TRANS_EVT_CHECKDEPS_DONE: + case ALPM_TRANS_EVT_RESOLVEDEPS_DONE: + case ALPM_TRANS_EVT_INTERCONFLICTS_DONE: + case ALPM_TRANS_EVT_INTEGRITY_DONE: + case ALPM_TRANS_EVT_DELTA_INTEGRITY_DONE: + case ALPM_TRANS_EVT_DELTA_PATCHES_DONE: + case ALPM_TRANS_EVT_DISKSPACE_DONE: /* nothing */ break; } @@ -252,21 +252,25 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) /* callback to handle questions from libalpm transactions (yes/no) */ /* TODO this is one of the worst ever functions written. void *data ? wtf */ -void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, +void cb_trans_conv(alpm_transconv_t event, void *data1, void *data2, void *data3, int *response) { switch(event) { - case PM_TRANS_CONV_INSTALL_IGNOREPKG: - *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"), - alpm_pkg_get_name(data1)); + case ALPM_TRANS_CONV_INSTALL_IGNOREPKG: + if(!config->op_s_downloadonly) { + *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"), + alpm_pkg_get_name(data1)); + } else { + *response = 1; + } break; - case PM_TRANS_CONV_REPLACE_PKG: + case ALPM_TRANS_CONV_REPLACE_PKG: *response = yesno(_(":: Replace %s with %s/%s?"), alpm_pkg_get_name(data1), (char *)data3, alpm_pkg_get_name(data2)); break; - case PM_TRANS_CONV_CONFLICT_PKG: + case ALPM_TRANS_CONV_CONFLICT_PKG: /* data parameters: target package, local package, conflict (strings) */ /* print conflict only if it contains new information */ if(strcmp(data1, data3) == 0 || strcmp(data2, data3) == 0) { @@ -282,7 +286,7 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, (char *)data2); } break; - case PM_TRANS_CONV_REMOVE_PKGS: + case ALPM_TRANS_CONV_REMOVE_PKGS: { alpm_list_t *unresolved = (alpm_list_t *) data1; alpm_list_t *namelist = NULL, *i; @@ -305,11 +309,11 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, alpm_list_free(namelist); } break; - case PM_TRANS_CONV_SELECT_PROVIDER: + case ALPM_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); + char *depstring = alpm_dep_compute_string((alpm_depend_t *)data2); printf(_(":: There are %d providers available for %s:\n"), count, depstring); free(depstring); @@ -317,7 +321,7 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, *response = select_question(count); } break; - case PM_TRANS_CONV_LOCAL_NEWER: + case ALPM_TRANS_CONV_LOCAL_NEWER: if(!config->op_s_downloadonly) { *response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"), alpm_pkg_get_name(data1), @@ -326,9 +330,11 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, *response = 1; } break; - case PM_TRANS_CONV_CORRUPTED_PKG: - *response = yesno(_(":: File %s is corrupted. Do you want to delete it?"), - (char *)data1); + case ALPM_TRANS_CONV_CORRUPTED_PKG: + *response = yesno(_(":: File %s is corrupted (%s).\n" + "Do you want to delete it?"), + (char *)data1, + alpm_strerror(*(enum _alpm_errno_t *)data2)); break; } if(config->noask) { @@ -340,7 +346,7 @@ 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, +void cb_trans_progress(alpm_transprog_t event, const char *pkgname, int percent, size_t howmany, size_t current) { /* size of line to allocate for text printing (e.g. not progressbar) */ @@ -352,7 +358,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, int len, wclen, wcwid, padwid; wchar_t *wcstr; - const int cols = getcols(0); + const int cols = getcols(); if(config->noprogressbar || cols == 0) { return; @@ -378,22 +384,22 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, /* set text of message to display */ switch (event) { - case PM_TRANS_PROGRESS_ADD_START: + case ALPM_TRANS_PROGRESS_ADD_START: opr = _("installing"); break; - case PM_TRANS_PROGRESS_UPGRADE_START: + case ALPM_TRANS_PROGRESS_UPGRADE_START: opr = _("upgrading"); break; - case PM_TRANS_PROGRESS_REMOVE_START: + case ALPM_TRANS_PROGRESS_REMOVE_START: opr = _("removing"); break; - case PM_TRANS_PROGRESS_CONFLICTS_START: + case ALPM_TRANS_PROGRESS_CONFLICTS_START: opr = _("checking for file conflicts"); break; - case PM_TRANS_PROGRESS_DISKSPACE_START: + case ALPM_TRANS_PROGRESS_DISKSPACE_START: opr = _("checking available disk space"); break; - case PM_TRANS_PROGRESS_INTEGRITY_START: + case ALPM_TRANS_PROGRESS_INTEGRITY_START: opr = _("checking package integrity"); break; default: @@ -401,7 +407,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, } infolen = cols * 6 / 10; - if (infolen < 50) { + if(infolen < 50) { infolen = 50; } @@ -495,12 +501,13 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) int totaldownload = 0; off_t xfered, total; - double rate = 0.0, timediff = 0.0, f_xfered = 0.0; + double rate = 0.0, timediff = 0.0; unsigned int eta_h = 0, eta_m = 0, eta_s = 0; + double rate_human, xfered_human; + const char *rate_label, *xfered_label; int file_percent = 0, total_percent = 0; - char rate_size = 'K', xfered_size = 'K'; - const int cols = getcols(0); + const int cols = getcols(); if(config->noprogressbar || cols == 0 || file_total == -1) { if(file_xfered == 0) { @@ -511,7 +518,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) } infolen = cols * 6 / 10; - if (infolen < 50) { + if(infolen < 50) { infolen = 50; } /* explanation of magic 28 number at the end */ @@ -563,7 +570,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) diff_usec = current_time.tv_usec - initial_time.tv_usec; timediff = diff_sec + (diff_usec / 1000000.0); if(timediff > 0.0) { - rate = xfered / (timediff * 1024.0); + rate = xfered / timediff; /* round elapsed time to the nearest second */ eta_s = (unsigned int)(timediff + 0.5); } else { @@ -577,11 +584,11 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) /* return if the calling interval was too short */ return; } - rate = (xfered - xfered_last) / (timediff * 1024.0); + rate = (xfered - xfered_last) / timediff; /* average rate to reduce jumpiness */ rate = (rate + 2 * rate_last) / 3; if(rate > 0.0) { - eta_s = (total - xfered) / (rate * 1024.0); + eta_s = (total - xfered) / rate; } else { eta_s = UINT_MAX; } @@ -611,10 +618,17 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) eta_m = eta_s / 60; eta_s -= eta_m * 60; - fname = strdup(filename); + /* allocate length+1 (plus null) in case we need to exchange .db for .sig */ + fname = calloc(1, strlen(filename) + 2); + strcpy(fname, filename); /* strip package or DB extension for cleaner look */ if((p = strstr(fname, ".pkg")) || (p = strstr(fname, ".db"))) { - *p = '\0'; + *p = '\0'; + + /* tack on a .sig suffix for signatures */ + if((p = strstr(filename, ".sig"))) { + strcat(fname, ".sig"); + } } /* In order to deal with characters from all locales, we have to worry * about wide characters and their column widths. A lot of stuff is @@ -630,50 +644,26 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) /* if padwid is < 0, we need to trim the string so padwid = 0 */ if(padwid < 0) { int i = filenamelen - 3; - wchar_t *p = wcfname; + wchar_t *wcp = wcfname; /* grab the max number of char columns we can fill */ - while(i > 0 && wcwidth(*p) < i) { - i -= wcwidth(*p); - p++; + while(i > 0 && wcwidth(*wcp) < i) { + i -= wcwidth(*wcp); + wcp++; } /* then add the ellipsis and fill out any extra padding */ - wcscpy(p, L"..."); + wcscpy(wcp, L"..."); padwid = i; } - /* Awesome formatting for progress bar. We need a mess of Kb->Mb->Gb stuff - * here. We'll use limit of 2048 for each until we get some empirical */ - /* rate_size = 'K'; was set above */ - if(rate > 2048.0) { - rate /= 1024.0; - rate_size = 'M'; - if(rate > 2048.0) { - rate /= 1024.0; - rate_size = 'G'; - /* we should not go higher than this for a few years (9999.9 Gb/s?)*/ - } - } - - f_xfered = xfered / 1024.0; /* convert to K by default */ - /* xfered_size = 'K'; was set above */ - if(f_xfered > 2048.0) { - f_xfered /= 1024.0; - xfered_size = 'M'; - if(f_xfered > 2048.0) { - f_xfered /= 1024.0; - xfered_size = 'G'; - /* I should seriously hope that archlinux packages never break - * the 9999.9GB mark... we'd have more serious problems than the progress - * bar in pacman */ - } - } + rate_human = humanize_size((off_t)rate, '\0', 0, &rate_label); + xfered_human = humanize_size(xfered, '\0', 0, &xfered_label); /* 1 space + filenamelen + 1 space + 7 for size + 1 + 7 for rate + 2 for /s + 1 space + 8 for eta */ /* TODO: if eta_h > 99, formatting gets all messed up */ - printf(" %ls%-*s %6.1f%c %#6.1f%c/s %02u:%02u:%02u", wcfname, - padwid, "", f_xfered, xfered_size, - rate, rate_size, eta_h, eta_m, eta_s); + printf(" %ls%-*s %6.1f%s %#6.1f%s/s %02u:%02u:%02u", wcfname, + padwid, "", xfered_human, xfered_label, rate_human, rate_label, + eta_h, eta_m, eta_s); free(fname); free(wcfname); @@ -687,7 +677,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, const char *fmt, va_list args) +void cb_log(alpm_loglevel_t level, const char *fmt, va_list args) { if(!fmt || strlen(fmt) == 0) { return; |