[pacman-dev] CVS update of pacman-lib (10 files)

Aaron Griffin aaron at archlinux.org
Sun Feb 4 03:26:53 EST 2007


    Date: Sunday, February 4, 2007 @ 03:26:53
  Author: aaron
    Path: /home/cvs-pacman/pacman-lib

Modified: lib/libalpm/alpm.c (1.110 -> 1.111)
          lib/libalpm/alpm.h (1.70 -> 1.71)
          lib/libalpm/package.c (1.56 -> 1.57)
          lib/libalpm/package.h (1.24 -> 1.25)
          lib/libalpm/sync.c (1.97 -> 1.98) src/pacman/conf.h (1.14 -> 1.15)
          src/pacman/pacman.c (1.86 -> 1.87)
          src/pacman/query.c (1.21 -> 1.22) src/pacman/util.c (1.26 -> 1.27)
          src/pacman/util.h (1.15 -> 1.16)

Implemented a crappy version of -Qu (query upgrades).  This simply outputs the
packages to be upgraded in a -Su operation.  Much of the code is duplicated from
sync.c.
TODO: move the implementation to upgrades.c, and reimplement the sync_sysupgrade
function in terms of this:
    trans->packages = alpm_get_upgrades();


-----------------------+
 lib/libalpm/alpm.c    |  154 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/libalpm/alpm.h    |    2 
 lib/libalpm/package.c |   11 +++
 lib/libalpm/package.h |    2 
 lib/libalpm/sync.c    |   15 ----
 src/pacman/conf.h     |    1 
 src/pacman/pacman.c   |    2 
 src/pacman/query.c    |   13 ++++
 src/pacman/util.c     |    4 -
 src/pacman/util.h     |    2 
 10 files changed, 188 insertions(+), 18 deletions(-)


Index: pacman-lib/lib/libalpm/alpm.c
diff -u pacman-lib/lib/libalpm/alpm.c:1.110 pacman-lib/lib/libalpm/alpm.c:1.111
--- pacman-lib/lib/libalpm/alpm.c:1.110	Wed Jan 31 01:10:21 2007
+++ pacman-lib/lib/libalpm/alpm.c	Sun Feb  4 03:26:52 2007
@@ -1078,4 +1078,158 @@
 
 /** @} */
 
+/* This function is mostly the same as sync.c find_replacements and sysupgrade
+ * functions, and we should be able to combine them - this is an interim
+ * solution made for -Qu operation */
+alpm_list_t *alpm_get_upgrades()
+{
+	int found = 0;
+	alpm_list_t *syncpkgs = NULL;
+	alpm_list_t *i, *j, *k;
+
+	ALPM_LOG_FUNC;
+
+	/* TODO holy nested loops, Batman! */
+	/* check for "recommended" package replacements */
+	_alpm_log(PM_LOG_DEBUG, _("checking for package replacements"));
+	for(i = handle->dbs_sync; i; i = i->next) {
+		for(j = _alpm_db_get_pkgcache(i->data, INFRQ_DESC); j; j = j->next) {
+			pmpkg_t *spkg = j->data;
+			for(k = spkg->replaces; k; k = k->next) {
+				alpm_list_t *m;
+				for(m = _alpm_db_get_pkgcache(handle->db_local, INFRQ_NONE); m; m = m->next) {
+					pmpkg_t *lpkg = m->data;
+					if(strcmp(k->data, lpkg->name) == 0) {
+						_alpm_log(PM_LOG_DEBUG, _("checking replacement '%s' for package '%s'"), k->data, spkg->name);
+						if(alpm_list_find_str(handle->ignorepkg, lpkg->name)) {
+							_alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (to be replaced by %s-%s)"),
+												lpkg->name, lpkg->version, spkg->name, spkg->version);
+						} else {
+							/* assume all replaces=() packages are accepted */
+							pmsyncpkg_t *sync = NULL;
+							pmpkg_t *dummy = _alpm_pkg_new(lpkg->name, NULL);
+							if(dummy == NULL) {
+								pm_errno = PM_ERR_MEMORY;
+								goto error;
+							}
+							dummy->requiredby = alpm_list_strdup(lpkg->requiredby);
+							/* check if spkg->name is already in the packages list. */
+							alpm_list_t *s;
+							for(s = syncpkgs; s && !found; s = s->next) {
+								sync = i->data;
+								if(sync && !strcmp(sync->pkg->name, spkg->name)) {
+									found = 1;
+								}
+							}
+
+							if(found) {
+								/* found it -- just append to the replaces list */
+								sync->data = alpm_list_add(sync->data, dummy);
+							} else {
+								/* none found -- enter pkg into the final sync list */
+								sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL);
+								if(sync == NULL) {
+									FREEPKG(dummy);
+									pm_errno = PM_ERR_MEMORY;
+									goto error;
+								}
+								sync->data = alpm_list_add(NULL, dummy);
+								syncpkgs = alpm_list_add(syncpkgs, sync);
+							}
+							_alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (to be replaced by %s-%s)"),
+												lpkg->name, lpkg->version, spkg->name, spkg->version);
+						}
+						break;
+					}
+				}
+			}
+		}
+	}
+
+	/* now do normal upgrades */
+	for(i = _alpm_db_get_pkgcache(handle->db_local, INFRQ_NONE); i; i = i->next) {
+		int cmp;
+		int replace=0;
+		pmpkg_t *local = i->data;
+		pmpkg_t *spkg = NULL;
+		pmsyncpkg_t *sync;
+
+		for(j = handle->dbs_sync; !spkg && j; j = j->next) {
+			spkg = _alpm_db_get_pkgfromcache(j->data, local->name);
+		}
+		if(spkg == NULL) {
+			_alpm_log(PM_LOG_DEBUG, _("'%s' not found in sync db -- skipping"), local->name);
+			continue;
+		}
+
+		/* we don't care about a to-be-replaced package's newer version */
+		for(j = syncpkgs; j && !replace; j=j->next) {
+			sync = j->data;
+			if(sync->type == PM_SYNC_TYPE_REPLACE) {
+				if(_alpm_pkg_isin(spkg->name, sync->data)) {
+					replace=1;
+				}
+			}
+		}
+		if(replace) {
+			_alpm_log(PM_LOG_DEBUG, _("'%s' is already elected for removal -- skipping"),
+								local->name);
+			continue;
+		}
+
+		/* 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 {
+			_alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (%s => %s)"),
+								local->name, local->version, local->version, spkg->version);
+			alpm_list_t *s;
+			pmsyncpkg_t *sync = NULL;
+			found = 0;
+			for(s = syncpkgs; s && !found; s = s->next) {
+				sync = i->data;
+				if(sync && strcmp(sync->pkg->name, local->name) == 0) {
+					found = 1;
+				}
+			}
+
+			if(!found) {
+				pmpkg_t *dummy = _alpm_pkg_new(local->name, local->version);
+				if(dummy == NULL) {
+					goto error;
+				}
+				sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy);
+				if(sync == NULL) {
+					FREEPKG(dummy);
+					goto error;
+				}
+				syncpkgs = alpm_list_add(syncpkgs, sync);
+			}
+		}
+	}
+
+	return(syncpkgs);
+error:
+	if(syncpkgs) {
+		alpm_list_free_inner(syncpkgs, _alpm_sync_free);
+		alpm_list_free(syncpkgs);
+	}
+	return(NULL);
+}
+
 /* vim: set ts=2 sw=2 noet: */
Index: pacman-lib/lib/libalpm/alpm.h
diff -u pacman-lib/lib/libalpm/alpm.h:1.70 pacman-lib/lib/libalpm/alpm.h:1.71
--- pacman-lib/lib/libalpm/alpm.h:1.70	Wed Jan 31 01:10:21 2007
+++ pacman-lib/lib/libalpm/alpm.h	Sun Feb  4 03:26:52 2007
@@ -486,6 +486,8 @@
 /* Version Compare */
 int alpm_versioncmp(const char *a, const char *b);
 
+alpm_list_t *alpm_get_upgrades();
+
 #ifdef __cplusplus
 }
 #endif
Index: pacman-lib/lib/libalpm/package.c
diff -u pacman-lib/lib/libalpm/package.c:1.56 pacman-lib/lib/libalpm/package.c:1.57
--- pacman-lib/lib/libalpm/package.c:1.56	Sat Feb  3 22:24:32 2007
+++ pacman-lib/lib/libalpm/package.c	Sun Feb  4 03:26:52 2007
@@ -834,4 +834,15 @@
 	return pkg->scriptlet;
 }
 
+int _alpm_pkg_istoonew(pmpkg_t *pkg)
+{
+	time_t t;
+
+	ALPM_LOG_FUNC;
+
+	if (!handle->upgradedelay)
+		return 0;
+	time(&t);
+	return((pkg->date + handle->upgradedelay) > t);
+}
 /* vim: set ts=2 sw=2 noet: */
Index: pacman-lib/lib/libalpm/package.h
diff -u pacman-lib/lib/libalpm/package.h:1.24 pacman-lib/lib/libalpm/package.h:1.25
--- pacman-lib/lib/libalpm/package.h:1.24	Tue Jan 23 22:02:54 2007
+++ pacman-lib/lib/libalpm/package.h	Sun Feb  4 03:26:52 2007
@@ -97,7 +97,7 @@
 pmpkg_t *_alpm_pkg_load(char *pkgfile);
 pmpkg_t *_alpm_pkg_isin(char *needle, alpm_list_t *haystack);
 int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch);
-
+int _alpm_pkg_istoonew(pmpkg_t *pkg);
 
 #endif /* _ALPM_PACKAGE_H */
 
Index: pacman-lib/lib/libalpm/sync.c
diff -u pacman-lib/lib/libalpm/sync.c:1.97 pacman-lib/lib/libalpm/sync.c:1.98
--- pacman-lib/lib/libalpm/sync.c:1.97	Wed Jan 31 22:31:46 2007
+++ pacman-lib/lib/libalpm/sync.c	Sun Feb  4 03:26:52 2007
@@ -115,18 +115,6 @@
 	return(sync);
 }
 
-static int istoonew(pmpkg_t *pkg)
-{
-	time_t t;
-
-	ALPM_LOG_FUNC;
-
-	if (!handle->upgradedelay)
-		return 0;
-	time(&t);
-	return((pkg->date + handle->upgradedelay) > t);
-}
-
 /* Find recommended replacements for packages during a sync.
  * (refactored from _alpm_sync_prepare)
  */
@@ -198,6 +186,7 @@
 	return(-1);
 }
 
+/* TODO reimplement this in terms of alpm_get_upgrades */
 int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync)
 {
 	alpm_list_t *i, *j;
@@ -252,7 +241,7 @@
 				/* package should be ignored (IgnorePkg) */
 				_alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)"),
 									local->name, local->version, spkg->version);
-			} else if(istoonew(spkg)) {
+			} 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);
Index: pacman-lib/src/pacman/conf.h
diff -u pacman-lib/src/pacman/conf.h:1.14 pacman-lib/src/pacman/conf.h:1.15
--- pacman-lib/src/pacman/conf.h:1.14	Wed Jan 31 01:10:22 2007
+++ pacman-lib/src/pacman/conf.h	Sun Feb  4 03:26:53 2007
@@ -43,6 +43,7 @@
 	unsigned short op_q_owns;
 	unsigned short op_q_search;
 	unsigned short op_q_changelog;
+	unsigned short op_q_upgrade;
 	unsigned short op_s_clean;
 	unsigned short op_s_dependsonly;
 	unsigned short op_s_downloadonly;
Index: pacman-lib/src/pacman/pacman.c
diff -u pacman-lib/src/pacman/pacman.c:1.86 pacman-lib/src/pacman/pacman.c:1.87
--- pacman-lib/src/pacman/pacman.c:1.86	Sat Feb  3 20:36:45 2007
+++ pacman-lib/src/pacman/pacman.c	Sun Feb  4 03:26:53 2007
@@ -372,7 +372,7 @@
 				break;
 			case 'u':
 				config->op_s_upgrade = 1;
-				/* TODO config->op_q_upgrade = 1; */
+				config->op_q_upgrade = 1;
 				break;
 			case 'v': (config->verbose)++; break;
 			case 'w':
Index: pacman-lib/src/pacman/query.c
diff -u pacman-lib/src/pacman/query.c:1.21 pacman-lib/src/pacman/query.c:1.22
--- pacman-lib/src/pacman/query.c:1.21	Wed Jan 31 03:00:50 2007
+++ pacman-lib/src/pacman/query.c	Sun Feb  4 03:26:53 2007
@@ -124,6 +124,19 @@
 		}
 	}
 
+	if(config->op_q_upgrade) {
+		MSG(NL, _("Checking for package upgrades"));
+		alpm_list_t *syncpkgs;
+
+		if((syncpkgs = alpm_get_upgrades()) != NULL) {
+				display_targets(syncpkgs);
+				return(0);
+		} else {
+			MSG(NL, _("no upgrades found"));
+			return(1);
+		}
+	}
+
 	for(i = targets; !done; i = (i ? alpm_list_next(i) : NULL)) {
 		if(targets == NULL) {
 			done = 1;
Index: pacman-lib/src/pacman/util.c
diff -u pacman-lib/src/pacman/util.c:1.26 pacman-lib/src/pacman/util.c:1.27
--- pacman-lib/src/pacman/util.c:1.26	Sat Feb  3 20:36:45 2007
+++ pacman-lib/src/pacman/util.c	Sun Feb  4 03:26:53 2007
@@ -263,14 +263,14 @@
  * `pkgs` should be a list of pmsyncpkg_t's,
  * retrieved from a transaction object
  */
-void display_targets(alpm_list_t *pkgs)
+void display_targets(alpm_list_t *syncpkgs)
 {
 	char *str;
 	alpm_list_t *i, *j;
 	alpm_list_t *targets = NULL, *to_remove = NULL;
 	unsigned long totalsize = 0, totalisize = 0, totalrsize = 0;
 
-	for(i = pkgs; i; i = alpm_list_next(i)) {
+	for(i = syncpkgs; i; i = alpm_list_next(i)) {
 		pmsyncpkg_t *sync = alpm_list_getdata(i);
 		pmpkg_t *pkg = alpm_sync_get_package(sync);
 
Index: pacman-lib/src/pacman/util.h
diff -u pacman-lib/src/pacman/util.h:1.15 pacman-lib/src/pacman/util.h:1.16
--- pacman-lib/src/pacman/util.h:1.15	Sat Feb  3 20:36:45 2007
+++ pacman-lib/src/pacman/util.h	Sun Feb  4 03:26:53 2007
@@ -59,7 +59,7 @@
 char *strtrim(char *str);
 int reg_match(char *string, char *pattern);
 void list_display(const char *title, alpm_list_t *list);
-void display_targets(alpm_list_t *pkgs);
+void display_targets(alpm_list_t *syncpkgs);
 float get_update_timediff(int first_call);
 void fill_progress(const int percent, const int proglen);
 




More information about the pacman-dev mailing list