diff options
Diffstat (limited to 'src/pacman/package.c')
-rw-r--r-- | src/pacman/package.c | 172 |
1 files changed, 85 insertions, 87 deletions
diff --git a/src/pacman/package.c b/src/pacman/package.c index 5c27b665..ac3f8207 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -1,8 +1,8 @@ /* * package.c - * + * * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ @@ -26,25 +26,28 @@ #include <string.h> #include <limits.h> #include <sys/stat.h> -#include <libintl.h> #include <alpm.h> #include <alpm_list.h> /* pacman */ #include "package.h" -#include "log.h" #include "util.h" -/* Display the content of an installed package +/* Display the content of a package * - * level: <1 - omits N/A info for file query (-Qp) - * 1 - normal level - * >1 - extra information (backup files) + * level: <0 - sync package [-Si] + * =0 - file query [-Qip] + * 1 - localdb query, normal level [-Qi] + * >1 - localdb query, extra information (backup files) [-Qii] */ void dump_pkg_full(pmpkg_t *pkg, int level) { - const char *bdate, *type, *idate, *reason, *descheader; + const char *reason, *descheader; + time_t bdate, idate; + char bdatestr[50] = "", idatestr[50] = ""; + const alpm_list_t *i; + alpm_list_t *requiredby = NULL, *depstrings = NULL; if(pkg == NULL) { return; @@ -52,8 +55,13 @@ void dump_pkg_full(pmpkg_t *pkg, int level) /* set variables here, do all output below */ bdate = alpm_pkg_get_builddate(pkg); - type = alpm_pkg_get_buildtype(pkg); + if(bdate) { + strftime(bdatestr, 50, "%c", localtime(&bdate)); + } idate = alpm_pkg_get_installdate(pkg); + if(idate) { + strftime(idatestr, 50, "%c", localtime(&idate)); + } switch((long)alpm_pkg_get_reason(pkg)) { case PM_PKG_REASON_EXPLICIT: @@ -67,86 +75,89 @@ void dump_pkg_full(pmpkg_t *pkg, int level) break; } + /* 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); + depstrings = alpm_list_add(depstrings, alpm_dep_get_string(dep)); + } + + if(level>0) { + /* compute this here so we don't get a puase in the middle of output */ + requiredby = alpm_pkg_compute_requiredby(pkg); + } + descheader = _("Description : "); /* actual output */ - printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg)); - printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg)); - printf(_("URL : %s\n"), (char *)alpm_pkg_get_url(pkg)); - list_display(_("License :"), alpm_pkg_get_licenses(pkg)); + if(level == 0) { + string_display(_("Filename :"), alpm_pkg_get_filename(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)); + list_display(_("Licenses :"), alpm_pkg_get_licenses(pkg)); list_display(_("Groups :"), alpm_pkg_get_groups(pkg)); list_display(_("Provides :"), alpm_pkg_get_provides(pkg)); - list_display(_("Depends On :"), alpm_pkg_get_depends(pkg)); - list_display(_("Removes :"), alpm_pkg_get_removes(pkg)); + list_display(_("Depends On :"), depstrings); + list_display(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg)); /* Only applicable if installed */ if(level > 0) { - list_display(_("Required By :"), alpm_pkg_get_requiredby(pkg)); + list_display(_("Required By :"), requiredby); + FREELIST(requiredby); } list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); - printf(_("Installed Size : %6.2f K\n"), (float)alpm_pkg_get_size(pkg) / 1024.0); - printf(_("Packager : %s\n"), (char *)alpm_pkg_get_packager(pkg)); - printf(_("Architecture : %s\n"), (char *)alpm_pkg_get_arch(pkg)); - printf(_("Build Date : %s %s\n"), bdate, strlen(bdate) ? "UTC" : ""); - printf(_("Build Type : %s\n"), strlen(type) ? type : _("Unknown")); + list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); + if(level < 0) { + printf(_("Download Size : %6.2f K\n"), + (float)alpm_pkg_get_size(pkg) / 1024.0); + } + if(level == 0) { + printf(_("Compressed Size: %6.2f K\n"), + (float)alpm_pkg_get_size(pkg) / 1024.0); + } + + printf(_("Installed Size : %6.2f K\n"), + (float)alpm_pkg_get_isize(pkg) / 1024.0); + string_display(_("Packager :"), alpm_pkg_get_packager(pkg)); + string_display(_("Architecture :"), alpm_pkg_get_arch(pkg)); + string_display(_("Build Date :"), bdatestr); if(level > 0) { - printf(_("Install Date : %s %s\n"), idate, strlen(idate) ? "UTC" : ""); - printf(_("Install Reason : %s\n"), reason); + string_display(_("Install Date :"), idatestr); + string_display(_("Install Reason :"), reason); + } + if(level >= 0) { + string_display(_("Install Script :"), + alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No")); + } + + /* MD5 Sum for sync package */ + if(level < 0) { + string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg)); } - printf(_("Install Script : %s\n"), - alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No")); /* printed using a variable to make i18n safe */ printf("%s", descheader); indentprint(alpm_pkg_get_desc(pkg), mbstowcs(NULL, descheader, 0)); - printf("\n"); + printf("\n\n"); /* Print additional package info if info flag passed more than once */ if(level > 1) { - /* call new backup function */ - printf("\n"); dump_pkg_backups(pkg); + printf("\n"); } - printf("\n"); + + FREELIST(depstrings); } /* Display the content of a sync package */ void dump_pkg_sync(pmpkg_t *pkg, const char *treename) { - char *descheader, *md5sum, *sha1sum; if(pkg == NULL) { return; } - - descheader = _("Description : "); - - md5sum = (char *)alpm_pkg_get_md5sum(pkg); - sha1sum = (char *)alpm_pkg_get_sha1sum(pkg); - - printf(_("Repository : %s\n"), treename); - printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg)); - printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg)); - list_display(_("Groups :"), alpm_pkg_get_groups(pkg)); - list_display(_("Provides :"), alpm_pkg_get_provides(pkg)); - list_display(_("Depends On :"), alpm_pkg_get_depends(pkg)); - list_display(_("Removes :"), alpm_pkg_get_removes(pkg)); - list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); - list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); - printf(_("Download Size : %6.2f K\n"), (float)alpm_pkg_get_size(pkg) / 1024.0); - printf(_("Installed Size : %6.2f K\n"), (float)alpm_pkg_get_isize(pkg) / 1024.0); - - /* printed using a variable to make i18n safe */ - printf("%s", descheader); - indentprint(alpm_pkg_get_desc(pkg), mbstowcs(NULL, descheader, 0)); - printf("\n"); - - if (md5sum != NULL && md5sum[0] != '\0') { - printf(_("MD5 Sum : %s"), md5sum); - } - if (sha1sum != NULL && sha1sum[0] != '\0') { - printf(_("SHA1 Sum : %s"), sha1sum); - } - printf("\n"); + string_display(_("Repository :"), treename); + dump_pkg_full(pkg, -1); } /* Display list of backup files and their modification states @@ -164,7 +175,7 @@ void dump_pkg_backups(pmpkg_t *pkg) char *str = strdup(alpm_list_getdata(i)); char *ptr = index(str, '\t'); if(ptr == NULL) { - FREE(str); + free(str); continue; } *ptr = '\0'; @@ -172,48 +183,39 @@ void dump_pkg_backups(pmpkg_t *pkg) snprintf(path, PATH_MAX-1, "%s%s", root, str); /* if we find the file, calculate checksums, otherwise it is missing */ if(!stat(path, &buf)) { - char *sum; char *md5sum = alpm_get_md5sum(path); - char *sha1sum = alpm_get_sha1sum(path); - if(md5sum == NULL || sha1sum == NULL) { - ERR(NL, _("error calculating checksums for %s\n"), path); - FREE(str); + if(md5sum == NULL) { + fprintf(stderr, _("error: could not calculate checksums for %s\n"), + path); + free(str); continue; } - /* TODO Is this a good way to check type of backup stored? - * We aren't storing it anywhere in the database. */ - if (strlen(ptr) == 32) { - sum = md5sum; - } else { /*if (strlen(ptr) == 40) */ - sum = sha1sum; - } + /* if checksums don't match, file has been modified */ - if (strcmp(sum, ptr)) { + if (strcmp(md5sum, ptr)) { printf(_("MODIFIED\t%s\n"), path); } else { printf(_("Not Modified\t%s\n"), path); } - FREE(md5sum); - FREE(sha1sum); + free(md5sum); } else { printf(_("MISSING\t\t%s\n"), path); } - FREE(str); + free(str); } } else { /* package had no backup files */ printf(_("(none)\n")); } } - + /* List all files contained in a package */ void dump_pkg_files(pmpkg_t *pkg) { const char *pkgname, *root, *filestr; alpm_list_t *i, *pkgfiles; - struct stat buf; char path[PATH_MAX]; pkgname = alpm_pkg_get_name(pkg); @@ -224,11 +226,7 @@ void dump_pkg_files(pmpkg_t *pkg) filestr = (char*)alpm_list_getdata(i); /* build a path so we can stat the filename */ snprintf(path, PATH_MAX-1, "%s%s", root, filestr); - if(!stat(path, &buf) && S_ISDIR(buf.st_mode)) { - /* if we stat it and it is a dir, don't print */ - } else { - fprintf(stdout, "%s %s\n", pkgname, path); - } + fprintf(stdout, "%s %s\n", pkgname, path); } fflush(stdout); @@ -243,7 +241,7 @@ void dump_pkg_changelog(char *clfile, const char *pkgname) if((fp = fopen(clfile, "r")) == NULL) { - ERR(NL, _("No changelog available for '%s'.\n"), pkgname); + fprintf(stderr, _("error: no changelog available for '%s'.\n"), pkgname); return; } else |