diff options
Diffstat (limited to 'src/pacman/package.c')
-rw-r--r-- | src/pacman/package.c | 132 |
1 files changed, 65 insertions, 67 deletions
diff --git a/src/pacman/package.c b/src/pacman/package.c index 77a5ee72..afbac6b7 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -26,7 +26,6 @@ #include <unistd.h> #include <limits.h> #include <errno.h> -#include <wchar.h> #include <alpm.h> #include <alpm_list.h> @@ -34,23 +33,25 @@ /* pacman */ #include "package.h" #include "util.h" +#include "conf.h" #define CLBUF_SIZE 4096 -/* Display the content of a package - * - * levels: - * <-1 - sync package, extra information (required by) [-Sii] - * -1 - sync package, normal level [-Si] - * =0 - file query [-Qip] - * 1 - localdb query, normal level [-Qi] - * >1 - localdb query, extra information (backup files) [-Qii] +/** + * Display the details of a package. + * Extra information entails 'required by' info for sync packages and backup + * files info for local packages. + * @param pkg package to display information for + * @param from the type of package we are dealing with + * @param extra should we show extra information */ -void dump_pkg_full(pmpkg_t *pkg, int level) +void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra) { const char *reason; time_t bdate, idate; char bdatestr[50] = "", idatestr[50] = ""; + const char *label; + double size; const alpm_list_t *i; alpm_list_t *requiredby = NULL, *depstrings = NULL; @@ -69,10 +70,10 @@ void dump_pkg_full(pmpkg_t *pkg, int level) } switch((long)alpm_pkg_get_reason(pkg)) { - case PM_PKG_REASON_EXPLICIT: + case ALPM_PKG_REASON_EXPLICIT: reason = _("Explicitly installed"); break; - case PM_PKG_REASON_DEPEND: + case ALPM_PKG_REASON_DEPEND: reason = _("Installed as a dependency for another package"); break; default: @@ -82,16 +83,20 @@ void dump_pkg_full(pmpkg_t *pkg, int level) /* turn depends list into a text list */ for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) { - pmdepend_t *dep = (pmdepend_t*)alpm_list_getdata(i); + alpm_depend_t *dep = (alpm_depend_t *)alpm_list_getdata(i); depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep)); } - if(level > 0 || level < -1) { + if(extra || from == PKG_FROM_LOCALDB) { /* compute this here so we don't get a pause in the middle of output */ requiredby = alpm_pkg_compute_requiredby(pkg); } /* actual output */ + if(from == PKG_FROM_SYNCDB) { + string_display(_("Repository :"), + alpm_db_get_name(alpm_pkg_get_db(pkg))); + } string_display(_("Name :"), alpm_pkg_get_name(pkg)); string_display(_("Version :"), alpm_pkg_get_version(pkg)); string_display(_("URL :"), alpm_pkg_get_url(pkg)); @@ -100,42 +105,52 @@ void dump_pkg_full(pmpkg_t *pkg, int level) list_display(_("Provides :"), alpm_pkg_get_provides(pkg)); list_display(_("Depends On :"), depstrings); list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg)); - if(level > 0 || level < -1) { + if(extra || from == PKG_FROM_LOCALDB) { list_display(_("Required By :"), requiredby); } list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); - if(level < 0) { - printf(_("Download Size : %6.2f K\n"), - (double)alpm_pkg_get_size(pkg) / 1024.0); - } - if(level == 0) { - printf(_("Compressed Size: %6.2f K\n"), - (double)alpm_pkg_get_size(pkg) / 1024.0); + + size = humanize_size(alpm_pkg_get_size(pkg), 'K', 1, &label); + if(from == PKG_FROM_SYNCDB) { + printf(_("Download Size : %6.2f %s\n"), size, label); + } else if(from == PKG_FROM_FILE) { + printf(_("Compressed Size: %6.2f %s\n"), size, label); } - printf(_("Installed Size : %6.2f K\n"), - (double)alpm_pkg_get_isize(pkg) / 1024.0); + size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 1, &label); + printf(_("Installed Size : %6.2f %s\n"), size, label); + string_display(_("Packager :"), alpm_pkg_get_packager(pkg)); string_display(_("Architecture :"), alpm_pkg_get_arch(pkg)); string_display(_("Build Date :"), bdatestr); - if(level > 0) { + if(from == PKG_FROM_LOCALDB) { string_display(_("Install Date :"), idatestr); string_display(_("Install Reason :"), reason); } - if(level >= 0) { + if(from == PKG_FROM_FILE || from == PKG_FROM_LOCALDB) { string_display(_("Install Script :"), alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No")); } - /* MD5 Sum for sync package */ - if(level < 0) { + if(from == PKG_FROM_SYNCDB) { string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg)); } + if(from == PKG_FROM_FILE) { + alpm_sigresult_t result; + int err = alpm_pkg_check_pgp_signature(pkg, &result); + if(err) { + string_display(_("Signatures :"), + alpm_strerror(alpm_errno(config->handle))); + } else { + signature_display(_("Signatures :"), &result); + } + alpm_sigresult_cleanup(&result); + } string_display(_("Description :"), alpm_pkg_get_desc(pkg)); /* Print additional package info if info flag passed more than once */ - if(level > 1) { + if(from == PKG_FROM_LOCALDB && extra) { dump_pkg_backups(pkg); } @@ -146,38 +161,26 @@ void dump_pkg_full(pmpkg_t *pkg, int level) FREELIST(requiredby); } -/* Display the content of a sync package - */ -void dump_pkg_sync(pmpkg_t *pkg, const char *treename, int level) -{ - if(pkg == NULL) { - return; - } - string_display(_("Repository :"), treename); - /* invert the level since we are a sync package */ - dump_pkg_full(pkg, -level); -} - static const char *get_backup_file_status(const char *root, - const char *filename, const char *expected_md5) + const alpm_backup_t *backup) { char path[PATH_MAX]; - char *ret; + const char *ret; - snprintf(path, PATH_MAX, "%s%s", root, filename); + snprintf(path, PATH_MAX, "%s%s", root, backup->name); /* if we find the file, calculate checksums, otherwise it is missing */ if(access(path, R_OK) == 0) { char *md5sum = alpm_compute_md5sum(path); if(md5sum == NULL) { - pm_fprintf(stderr, PM_LOG_ERROR, + pm_fprintf(stderr, ALPM_LOG_ERROR, _("could not calculate checksums for %s\n"), path); - return(NULL); + return NULL; } /* if checksums don't match, file has been modified */ - if (strcmp(md5sum, expected_md5) != 0) { + if(strcmp(md5sum, backup->hash) != 0) { ret = "MODIFIED"; } else { ret = "UNMODIFIED"; @@ -195,31 +198,26 @@ static const char *get_backup_file_status(const char *root, ret = "UNKNOWN"; } } - return(ret); + return ret; } /* Display list of backup files and their modification states */ -void dump_pkg_backups(pmpkg_t *pkg) +void dump_pkg_backups(alpm_pkg_t *pkg) { alpm_list_t *i; - const char *root = alpm_option_get_root(); + const char *root = alpm_option_get_root(config->handle); printf(_("Backup Files:\n")); if(alpm_pkg_get_backup(pkg)) { /* package has backup files, so print them */ for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) { + const alpm_backup_t *backup = alpm_list_getdata(i); const char *value; - char *str = strdup(alpm_list_getdata(i)); - char *ptr = strchr(str, '\t'); - if(ptr == NULL) { - free(str); + if(!backup->hash) { continue; } - *ptr = '\0'; - ptr++; - value = get_backup_file_status(root, str, ptr); - printf("%s\t%s%s\n", value, root, str); - free(str); + value = get_backup_file_status(root, backup); + printf("%s\t%s%s\n", value, root, backup->name); } } else { /* package had no backup files */ @@ -229,21 +227,21 @@ void dump_pkg_backups(pmpkg_t *pkg) /* List all files contained in a package */ -void dump_pkg_files(pmpkg_t *pkg, int quiet) +void dump_pkg_files(alpm_pkg_t *pkg, int quiet) { - const char *pkgname, *root, *filestr; + const char *pkgname, *root; alpm_list_t *i, *pkgfiles; pkgname = alpm_pkg_get_name(pkg); pkgfiles = alpm_pkg_get_files(pkg); - root = alpm_option_get_root(); + root = alpm_option_get_root(config->handle); for(i = pkgfiles; i; i = alpm_list_next(i)) { - filestr = alpm_list_getdata(i); + const alpm_file_t *file = alpm_list_getdata(i); if(!quiet){ - fprintf(stdout, "%s %s%s\n", pkgname, root, filestr); + fprintf(stdout, "%s %s%s\n", pkgname, root, file->name); } else { - fprintf(stdout, "%s%s\n", root, filestr); + fprintf(stdout, "%s%s\n", root, file->name); } } @@ -252,12 +250,12 @@ void dump_pkg_files(pmpkg_t *pkg, int quiet) /* Display the changelog of a package */ -void dump_pkg_changelog(pmpkg_t *pkg) +void dump_pkg_changelog(alpm_pkg_t *pkg) { void *fp = NULL; if((fp = alpm_pkg_changelog_open(pkg)) == NULL) { - pm_fprintf(stderr, PM_LOG_ERROR, _("no changelog available for '%s'.\n"), + pm_fprintf(stderr, ALPM_LOG_ERROR, _("no changelog available for '%s'.\n"), alpm_pkg_get_name(pkg)); return; } else { |