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

Aaron Griffin aaron at archlinux.org
Mon Jan 22 20:34:58 EST 2007


    Date: Monday, January 22, 2007 @ 20:34:58
  Author: aaron
    Path: /home/cvs-pacman/pacman-lib

Modified: lib/libalpm/alpm_list.c (1.2 -> 1.3)
          lib/libalpm/db.c (1.54 -> 1.55) lib/libalpm/group.c (1.11 -> 1.12)
          src/pacman/sync.c (1.95 -> 1.96)

* Added some calloc calls to replace the malloc-then-set-to-zero functionality
* Fixed -Ss output so as not to call alpm_list_getdata with a NULl list
* Added a NULL check in alpm_list_getdata
* Fixed alpm_list_add_sorted to properly handle a new / beginning insertions


-------------------------+
 lib/libalpm/alpm_list.c |    5 ++++-
 lib/libalpm/db.c        |    8 ++------
 lib/libalpm/group.c     |    5 +----
 src/pacman/sync.c       |   23 ++++++++++++++++-------
 4 files changed, 23 insertions(+), 18 deletions(-)


Index: pacman-lib/lib/libalpm/alpm_list.c
diff -u pacman-lib/lib/libalpm/alpm_list.c:1.2 pacman-lib/lib/libalpm/alpm_list.c:1.3
--- pacman-lib/lib/libalpm/alpm_list.c:1.2	Mon Jan 22 04:27:00 2007
+++ pacman-lib/lib/libalpm/alpm_list.c	Mon Jan 22 20:34:58 2007
@@ -145,8 +145,10 @@
 
 		if(prev != NULL) {
 			prev->next = add;       /*  In middle.  */
+		} else {
+			list = add; /* At beginning, or new list */
 		}
-
+		
 		return(list);
 	}
 }
@@ -369,6 +371,7 @@
  */
 void *alpm_list_getdata(const alpm_list_t *entry)
 {
+	if(entry == NULL) return(NULL);
 	return(entry->data);
 }
 
Index: pacman-lib/lib/libalpm/db.c
diff -u pacman-lib/lib/libalpm/db.c:1.54 pacman-lib/lib/libalpm/db.c:1.55
--- pacman-lib/lib/libalpm/db.c:1.54	Fri Jan 19 04:28:44 2007
+++ pacman-lib/lib/libalpm/db.c	Mon Jan 22 20:34:58 2007
@@ -55,14 +55,14 @@
 {
 	pmdb_t *db;
 
-	db = (pmdb_t *)malloc(sizeof(pmdb_t));
+	db = calloc(1, sizeof(pmdb_t));
 	if(db == NULL) {
 		_alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"),
 				  sizeof(pmdb_t));
 		RET_ERR(PM_ERR_MEMORY, NULL);
 	}
 
-	db->path = (char *)malloc(strlen(root)+strlen(dbpath)+strlen(treename)+2);
+	db->path = calloc(1, strlen(root)+strlen(dbpath)+strlen(treename)+2);
 	if(db->path == NULL) {
 		_alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"),
 				  strlen(root)+strlen(dbpath)+strlen(treename)+2);
@@ -73,10 +73,6 @@
 
 	STRNCPY(db->treename, treename, PATH_MAX);
 
-	db->pkgcache = NULL;
-	db->grpcache = NULL;
-	db->servers = NULL;
-
 	return(db);
 }
 
Index: pacman-lib/lib/libalpm/group.c
diff -u pacman-lib/lib/libalpm/group.c:1.11 pacman-lib/lib/libalpm/group.c:1.12
--- pacman-lib/lib/libalpm/group.c:1.11	Fri Jan 19 04:28:45 2007
+++ pacman-lib/lib/libalpm/group.c	Mon Jan 22 20:34:58 2007
@@ -36,16 +36,13 @@
 {
 	pmgrp_t* grp;
 
-	grp = (pmgrp_t *)malloc(sizeof(pmgrp_t));
+	grp = calloc(1, sizeof(pmgrp_t));
 	if(grp == NULL) {
 		_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"),
 		                        sizeof(pmgrp_t));
 		RET_ERR(PM_ERR_MEMORY, NULL);
 	}
 
-	grp->name[0] = '\0';
-	grp->packages = NULL;
-
 	return(grp);
 }
 
Index: pacman-lib/src/pacman/sync.c
diff -u pacman-lib/src/pacman/sync.c:1.95 pacman-lib/src/pacman/sync.c:1.96
--- pacman-lib/src/pacman/sync.c:1.95	Fri Jan 19 04:28:46 2007
+++ pacman-lib/src/pacman/sync.c	Mon Jan 22 20:34:58 2007
@@ -248,14 +248,20 @@
 				continue;
 			}
 			for(j = ret; j; j = alpm_list_next(j)) {
+				char *group = NULL;
+				alpm_list_t *grp;
 				pmpkg_t *pkg = alpm_list_getdata(j);
 
-				char *group = (char *)alpm_list_getdata(alpm_pkg_get_groups(pkg));
-				printf("%s/%s %s %s%s%s\n    ",
-							 alpm_db_get_name(db),
-						   alpm_pkg_get_name(pkg),
-						   alpm_pkg_get_version(pkg),
-						   (group ? " (" : ""), (group ? group : ""), (group ? ") " : ""));
+				printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
+						   alpm_pkg_get_version(pkg));
+
+				if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
+						group = alpm_list_getdata(grp);
+						printf(" (%s)\n    ", (char *)alpm_list_getdata(grp));
+				} else {
+					printf("\n    ");
+				}
+				
 				indentprint(alpm_pkg_get_desc(pkg), 4);
 				printf("\n\n");
 			}
@@ -280,9 +286,12 @@
 
 	if(targets) {
 		for(i = targets; i; i = alpm_list_next(i)) {
+			char *grpname = alpm_list_getdata(i);
 			for(j = syncs; j; j = alpm_list_next(j)) {
 				pmdb_t *db = alpm_list_getdata(j);
-				pmgrp_t *grp = alpm_db_readgrp(db, alpm_list_getdata(i));
+				printf("searching '%s' for groups '%s'\n", alpm_db_get_name(db), grpname);
+				fflush(stdout);
+				pmgrp_t *grp = alpm_db_readgrp(db, grpname);
 
 				if(grp) {
 					MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp));




More information about the pacman-dev mailing list