[pacman-dev] CVS update of pacman-lib/lib/libalpm (package.c sync.c)

Aaron Griffin aaron at archlinux.org
Tue Feb 6 12:39:32 EST 2007


    Date: Tuesday, February 6, 2007 @ 12:39:32
  Author: aaron
    Path: /home/cvs-pacman/pacman-lib/lib/libalpm

Modified: package.c (1.57 -> 1.58) sync.c (1.98 -> 1.99)

Attempt to unify the -S and -Su version comparissons for when a package is newer
See FS#5388


-----------+
 package.c |   32 ++++++++++++++++++++++++++++++++
 sync.c    |   34 +++-------------------------------
 2 files changed, 35 insertions(+), 31 deletions(-)


Index: pacman-lib/lib/libalpm/package.c
diff -u pacman-lib/lib/libalpm/package.c:1.57 pacman-lib/lib/libalpm/package.c:1.58
--- pacman-lib/lib/libalpm/package.c:1.57	Sun Feb  4 03:26:52 2007
+++ pacman-lib/lib/libalpm/package.c	Tue Feb  6 12:39:32 2007
@@ -122,6 +122,38 @@
 	return;
 }
 
+/* Is pkgB an upgrade for pkgA ? */
+int alpm_pkg_compare_versions(pmpkg_t *pkgA, pmpkg_t *pkgB)
+{
+	if(spkg->force) {
+		/* skip the version compare call if this is a 'force' package */
+		return(1);
+	}
+
+	/* compare versions and see if we need to upgrade */
+	int cmp = alpm_versioncmp(pkgA->version, pkgB->version);
+
+	if(cmp > 0 && !spkg->force) {
+		/* local version is newer */
+		pmdb_t *db = spkg->data;
+		_alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)"),
+							local->name, local->version, db->treename, spkg->version);
+		cmp = 0;
+	} else if(alpm_list_find_str(handle->ignorepkg, spkg->name)) {
+		/* package should be ignored (IgnorePkg) */
+		_alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)"),
+							local->name, local->version, spkg->version);
+		cmp = 0;
+	} else if(_alpm_pkg_istoonew(spkg)) {
+		/* package too new (UpgradeDelay) */
+		_alpm_log(PM_LOG_DEBUG, _("%s-%s: delaying upgrade of package (%s)"),
+							local->name, local->version, spkg->version);
+		cmp = 0;
+	}
+
+	return(cmp);
+}
+
 /* Helper function for comparing packages
  */
 int _alpm_pkg_cmp(const void *p1, const void *p2)
Index: pacman-lib/lib/libalpm/sync.c
diff -u pacman-lib/lib/libalpm/sync.c:1.98 pacman-lib/lib/libalpm/sync.c:1.99
--- pacman-lib/lib/libalpm/sync.c:1.98	Sun Feb  4 03:26:52 2007
+++ pacman-lib/lib/libalpm/sync.c	Tue Feb  6 12:39:32 2007
@@ -229,24 +229,7 @@
 			}
 
 			/* compare versions and see if we need to upgrade */
-			cmp = alpm_versioncmp(local->version, spkg->version);
-			if(cmp > 0 && !spkg->force) {
-				/* local version is newer */
-				pmdb_t *db = spkg->data;
-				_alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)"),
-									local->name, local->version, db->treename, spkg->version);
-			} else if(cmp == 0) {
-				/* versions are identical */
-			} else if(alpm_list_find_str(handle->ignorepkg, spkg->name)) {
-				/* package should be ignored (IgnorePkg) */
-				_alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)"),
-									local->name, local->version, spkg->version);
-			} else if(_alpm_pkg_istoonew(spkg)) {
-				/* package too new (UpgradeDelay) */
-				_alpm_log(PM_LOG_DEBUG, _("%s-%s: delaying upgrade of package (%s)"),
-									local->name, local->version, spkg->version);
-				/* check if spkg->name is already in the packages list. */
-			} else {
+			if(alpm_pkg_compare_versions(local, spkg)) {
 				_alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (%s => %s)"),
 									local->name, local->version, local->version, spkg->version);
 				if(!find_pkginsync(spkg->name, trans->packages)) {
@@ -260,8 +243,6 @@
 						goto error;
 					}
 					trans->packages = alpm_list_add(trans->packages, sync);
-				} else {
-					/* spkg->name is already in the packages list -- just ignore it */
 				}
 			}
 		}
@@ -344,17 +325,8 @@
 
 	local = _alpm_db_get_pkgfromcache(db_local, spkg->name);
 	if(local) {
-		cmp = alpm_versioncmp(local->version, spkg->version);
-		if(cmp > 0 && !spkg->force) {
-			/* local version is newer -- get confirmation before adding */
-			int resp = 0;
-			QUESTION(trans, PM_TRANS_CONV_LOCAL_NEWER, local, NULL, NULL, &resp);
-			if(!resp) {
-				_alpm_log(PM_LOG_WARNING, _("%s-%s: local version is newer -- skipping"), local->name, local->version);
-				return(0);
-			}
-		} else if(cmp == 0) {
-			/* versions are identical -- get confirmation before adding */
+		if(alpm_pkg_compare_versions(local, spkg) == 0) {
+			/* spkg is NOT an upgrade, get confirmation before adding */
 			int resp = 0;
 			QUESTION(trans, PM_TRANS_CONV_LOCAL_UPTODATE, local, NULL, NULL, &resp);
 			if(!resp) {




More information about the pacman-dev mailing list