[pacman-dev] [PATCH 3/3] Simplify package validation info output for sync packages

Allan McRae allan at archlinux.org
Mon Feb 20 00:07:15 EST 2012


Unify the output for local and sync packages by only printing a
list of possible validation types for sync packages.  This also
has the advantage of not printing the very long sha256 checksum
which line wrapped on a standard width terminal.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 lib/libalpm/be_sync.c |   24 ++++++++++++++++++++++++
 src/pacman/package.c  |   44 ++++++++++++++++++--------------------------
 2 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index a686def..a124dfa 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -296,6 +296,29 @@ cleanup:
 static int sync_db_read(alpm_db_t *db, struct archive *archive,
 		struct archive_entry *entry, alpm_pkg_t **likely_pkg);
 
+static alpm_pkgvalidation_t _sync_get_validation(alpm_pkg_t *pkg)
+{
+	if(pkg->validation) {
+		return pkg->validation;
+	}
+
+	if(pkg->md5sum) {
+		pkg->validation |= ALPM_PKG_VALIDATION_MD5SUM;
+	}
+	if(pkg->sha256sum) {
+		pkg->validation |= ALPM_PKG_VALIDATION_SHA256SUM;
+	}
+	if(pkg->base64_sig) {
+		pkg->validation |= ALPM_PKG_VALIDATION_SIGNATURE;
+	}
+
+	if(!pkg->validation) {
+		pkg->validation |= ALPM_PKG_VALIDATION_NONE;
+	}
+
+	return pkg->validation;
+}
+
 static alpm_pkg_t *load_pkg_for_entry(alpm_db_t *db, const char *entryname,
 		const char **entry_filename, alpm_pkg_t *likely_pkg)
 {
@@ -337,6 +360,7 @@ static alpm_pkg_t *load_pkg_for_entry(alpm_db_t *db, const char *entryname,
 		pkg->origin = PKG_FROM_SYNCDB;
 		pkg->origin_data.db = db;
 		pkg->ops = &default_pkg_ops;
+		pkg->ops->get_validation = _sync_get_validation;
 		pkg->handle = db->handle;
 
 		/* add to the collection */
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 5f824f4..6f78e56 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -95,25 +95,23 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
 			break;
 	}
 
-    if(from == PKG_FROM_LOCALDB) {
-		alpm_pkgvalidation_t v = alpm_pkg_get_validation(pkg);
-		if(v) {
-			if(v & ALPM_PKG_VALIDATION_NONE) {
-				validation = alpm_list_add(validation, strdup(_("None")));
-			} else {
-				if(v & ALPM_PKG_VALIDATION_MD5SUM) {
-					validation = alpm_list_add(validation, strdup(_("MD5 Sum")));
-				}
-				if(v & ALPM_PKG_VALIDATION_SHA256SUM) {
-					validation = alpm_list_add(validation, strdup(_("SHA256 Sum")));
-				}
-				if(v & ALPM_PKG_VALIDATION_SIGNATURE) {
-					validation = alpm_list_add(validation, strdup(_("Signature")));
-				}
-			}
+	alpm_pkgvalidation_t v = alpm_pkg_get_validation(pkg);
+	if(v) {
+		if(v & ALPM_PKG_VALIDATION_NONE) {
+			validation = alpm_list_add(validation, strdup(_("None")));
 		} else {
-			validation = alpm_list_add(validation, strdup(_("Unknown")));
+			if(v & ALPM_PKG_VALIDATION_MD5SUM) {
+				validation = alpm_list_add(validation, strdup(_("MD5 Sum")));
+			}
+			if(v & ALPM_PKG_VALIDATION_SHA256SUM) {
+				validation = alpm_list_add(validation, strdup(_("SHA256 Sum")));
+			}
+			if(v & ALPM_PKG_VALIDATION_SIGNATURE) {
+				validation = alpm_list_add(validation, strdup(_("Signature")));
+			}
 		}
+	} else {
+		validation = alpm_list_add(validation, strdup(_("Unknown")));
 	}
 
 	if(extra || from == PKG_FROM_LOCALDB) {
@@ -162,12 +160,8 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
 				alpm_pkg_has_scriptlet(pkg) ?  _("Yes") : _("No"));
 	}
 
-	if(from == PKG_FROM_SYNCDB) {
-		string_display(_("MD5 Sum        :"), alpm_pkg_get_md5sum(pkg));
-		string_display(_("SHA256 Sum     :"), alpm_pkg_get_sha256sum(pkg));
-		string_display(_("Signatures     :"),
-				alpm_pkg_get_base64_sig(pkg) ? _("Yes") : _("None"));
-	}
+	list_display(_("Validated By   :"), validation);
+
 	if(from == PKG_FROM_FILE) {
 		alpm_siglist_t siglist;
 		int err = alpm_pkg_check_pgp_signature(pkg, &siglist);
@@ -181,9 +175,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
 		}
 		alpm_siglist_cleanup(&siglist);
 	}
-	if(from == PKG_FROM_LOCALDB) {
-		list_display(_("Validated By   :"), validation);
-	}
+
 	string_display(_("Description    :"), alpm_pkg_get_desc(pkg));
 
 	/* Print additional package info if info flag passed more than once */
-- 
1.7.9.1



More information about the pacman-dev mailing list