PERFORCE change 145566 for review

Anders Nore andenore at FreeBSD.org
Mon Jul 21 17:22:02 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=145566

Change 145566 by andenore at andenore_laptop on 2008/07/21 17:21:09

	Various changes and bugfixes.

Affected files ...

.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#8 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile#4 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/Makefile#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#7 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/Makefile#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#5 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#8 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/info.h#4 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/main.c#8 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#5 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#6 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/Makefile#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#8 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#11 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/match.c#6 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#7 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/test.sh#1 add

Differences ...

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#8 (text+ko) ====

@@ -1,5 +1,5 @@
 Changes made to pkg_install during SoC2008 by Anders Nore (andenore at FreeBSD.org)
-Last modified: 2008 07 15
+Last modified: 2008 07 21
 
 
 Converter: 
@@ -13,6 +13,7 @@
 	  significantly.
 	- Uses human readable output for -s (size option) I'm not sure if this breaks
 	  things, but it looks Ok. (The old output is available via the -b option)
+	- Check installation date with -n (human readable) or -N (seconds since epoch)
 
 Add:
 	- Indexes information to dbcache according to the add

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile#4 (text+ko) ====

@@ -18,3 +18,5 @@
 		rm -rf pkg_install-${DATE})
 		
 	
+test:
+	./test.sh zip.tbz
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/Makefile#3 (text+ko) ====

@@ -11,4 +11,7 @@
 DPADD=	${LIBINSTALL} ${LIBFETCH} ${LIBMD}
 LDADD=	${LIBINSTALL} -lfetch -lmd
 
+test:
+	./test.sh
+
 .include <bsd.prog.mk>

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#7 (text+ko) ====


==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/Makefile#3 (text+ko) ====

@@ -2,7 +2,7 @@
 PROG=   pkg_convert
 SRCS=   perform.c main.c
 
-CFLAGS+= -I${.CURDIR}/../lib
+CFLAGS+= -I${.CURDIR}/../lib -g
 
 WARNS?= 3
 #WFORMAT?=       1

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#5 (text+ko) ====

@@ -2,7 +2,6 @@
 #include <lib.h>
 #include <getopt.h>
 
-char *Key		= NULL;
 Boolean CheckExists	= FALSE;
 Boolean Print		= FALSE;
 Boolean	Textual		= FALSE;
@@ -12,11 +11,11 @@
 static char opts[] = "vthep";
 
 static struct option longopts[] = {
-	{ "verbose",	no_argument,		NULL,		'v' },
-	{ "textual",	no_argument,		NULL,		't' },
-	{ "help",	no_argument,		NULL,		'h' },
-	{ "exist",	no_argument,		NULL,		'e' },
-	{ NULL,		0,			NULL,		0 }
+	{ "verbose",	no_argument,	NULL,	'v' },
+	{ "textual",	no_argument,	NULL,	't' },
+	{ "help",	no_argument,	NULL,	'h' },
+	{ "exist",	no_argument,	NULL,	'e' },
+	{ NULL,		0,		NULL,	0 }
 };
 
 
@@ -28,11 +27,6 @@
     signal(SIGHUP, cleanup);
     signal(SIGINT, cleanup);
 
-    if (argc == 1)
-	flags = O_CREAT | O_RDWR;
-    else
-	flags = O_RDONLY;
-
     pkgs = argv;
     while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) {
 	switch(ch) {
@@ -56,7 +50,12 @@
 	}
     }
 
-    if(openDatabase(flags)) {
+    if (!CheckExists && !Print)
+	flags = O_CREAT | O_RDWR;
+    else
+	flags = O_RDONLY;
+
+    if (openDatabase(flags)) {
 	err(1, "Could not open database: %s", DBCACHE_FILE);
     }
     atexit(closeDatabase);
@@ -81,7 +80,7 @@
 
     pkgs = argv;
 
-    if (argc == NULL)
+    if (argc == 0)
 	return pkg_perform(NULL);
     else
 	return pkg_perform(pkgs);

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#8 (text+ko) ====

@@ -59,7 +59,7 @@
 	    if (Verbose)
 		printf("Printing the whole database\n");
 	    DBT key;
-	    while (dbscan(database, &key, &data) == 0) {	
+	    while (dbScan(&key, &data) == 0) {	
 		printf("%-18s : %s\n", (char *)key.data, (char *)data.data);
 	    }
 	}

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/info.h#4 (text+ko) ====

@@ -66,6 +66,7 @@
 extern Boolean QUIET;
 extern Boolean UseBlkSz;
 extern Boolean KeepPackage;
+extern Boolean TimeEpoch;
 extern char *InfoPrefix;
 extern char PlayPen[];
 extern char *CheckPkg;

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/main.c#8 (text+ko) ====

@@ -32,6 +32,7 @@
 match_t	MatchType	= MATCH_GLOB;
 Boolean QUIET		= FALSE;
 Boolean UseBlkSz	= FALSE;
+Boolean TimeEpoch	= FALSE;
 char *InfoPrefix	= (char *)(uintptr_t)"";
 char PlayPen[FILENAME_MAX];
 char *CheckPkg		= NULL;
@@ -41,7 +42,7 @@
 
 static void usage(void);
 
-static char opts[] = "abcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:TvVW:xX";
+static char opts[] = "abcdDe:EfgGhiIjkKl:LmnNoO:pPqQrRst:TvVW:xX";
 static struct option longopts[] = {
 	{ "all",	no_argument,		NULL,		'a' },
 	{ "blocksize",	no_argument,		NULL,		'b' },
@@ -57,7 +58,8 @@
 	{ "template",	required_argument,	NULL,		't' },
 	{ "verbose",	no_argument,		NULL,		'v' },
 	{ "version",	no_argument,		NULL,		'P' },
-	{ "time",	no_argument,		NULL,		'T' },
+	{ "time",	no_argument,		NULL,		'n' },
+	{ "time-epoch",	no_argument,		NULL,		'N' },
 	{ "which",	required_argument,	NULL,		'W' },
 };
 
@@ -200,8 +202,14 @@
 	    strlcpy(PlayPen, optarg, sizeof(PlayPen));
 	    break;
 
-	case 'T':
+	case 'n':
+	    Flags |= SHOW_DATE;
+	    break;
+
+	case 'N':
 	    Flags |= SHOW_DATE;
+	    TimeEpoch = TRUE;
+	    break;
 
 	case 'x':
 	    MatchType = MATCH_REGEX;

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#5 (text+ko) ====

@@ -31,7 +31,7 @@
 .Nd a utility for displaying information on software packages
 .Sh SYNOPSIS
 .Nm
-.Op Fl bcdDEfghGiIjkKLmopPqQrRsvVxX
+.Op Fl bcdDEfghGiIjkKLmnNopPqQrRsvVxX
 .Op Fl e Ar package
 .Op Fl l Ar prefix
 .Op Fl t Ar template
@@ -143,8 +143,10 @@
 .Fx
 .Em "Ports Collection"
 of the underlying port from which the package was generated.
-.It Fl T
+.It Fl n
 Shows the time and date of installation
+.It Fl N
+Shows the time in seconds-since-epoch of the installalation
 .It Fl G , -no-glob
 Do not try to expand shell glob patterns in the
 .Ar pkg-name

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#6 (text+ko) ====

@@ -411,7 +411,13 @@
     if (!Quiet)
 	printf("%s%s", InfoPrefix, title);
 
-    printf("%s\n", datetime ? ctime(&datetime) : "No recorded installation time");
-
+    if (datetime) {
+	if (TimeEpoch)
+	    printf("%d\n", (int)(datetime));
+	else
+	    printf("%s\n", ctime(&datetime));
+    }
+    else
+	printf("No recorder installation time\n");
 }
 

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/Makefile#3 (text+ko) ====

@@ -4,7 +4,7 @@
 INTERNALLIB=
 SRCS=	file.c msg.c plist.c str.c exec.c global.c pen.c database.c match.c \
 	deps.c version.c pkgwrap.c url.c 
-CFLAGS=	-g
+CFLAGS=
 
 WARNS?=	3
 WFORMAT?=	1

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#8 (text+ko) ====

@@ -184,13 +184,18 @@
 
 /*
  * Scans the database, returning a new key/data pair for each call
- * Returns 1 when finished
+ * Returns 1 when finished, -1 on error, 0 on success
  */
 int
 dbscan(const DB *db, DBT *key, DBT *data) {
 	return db->seq(db, key, data, R_NEXT);
 }
 
+int
+dbScan(DBT *key, DBT *data) {
+	return database->seq(database, key, data, R_NEXT);
+}
+
 
 /*
  * Close the database file
@@ -215,57 +220,59 @@
 
 /*
  * cache_plist
+ * Caches the information about the package pkg into the database
  */
 int
 cache_plist(Package *pkg, Boolean showmsg)
 {
-	PackingList itr = NULL;
-	Boolean skip = FALSE;
-	char *cwd;
-	DBT key, data;
+    PackingList itr = NULL;
+    Boolean skip = FALSE;
+    char *cwd;
+    DBT key, data;
 
-	if (pkg->name == NULL || pkg->origin == NULL) {
-		if(showmsg)
-			warnx("%s does not appear to be a valid package!", pkg->name);
-		return 1;
-	}
+    if (pkg->name == NULL || pkg->origin == NULL) {
+	if(showmsg)
+	    warnx("%s does not appear to be a valid package!", pkg->name);
+	return 1;
+    }
 
-	key.size = strlen(pkg->name) + 1;
-	key.data = (char *)pkg->name;
-	data.size = strlen(pkg->origin) + 1;
-	data.data = (char *)pkg->origin;
+    key.size = strlen(pkg->name) + 1;
+    key.data = (char *)pkg->name;
+    data.size = strlen(pkg->origin) + 1;
+    data.data = (char *)pkg->origin;
 
-	if(showmsg)
-		printf("Saving package: %s\n", (char *)key.data);
-	dbsave(&key, &data);
+    if(showmsg)
+	printf("Saving package: %s\n", (char *)key.data);
+    dbsave(&key, &data);
 
-	for (itr = pkg->head; itr != pkg->tail; itr = itr->next) {
-		if (itr->type == PLIST_CWD && skip == FALSE) {
-			cwd = itr->name;
-		} 
-		else if (itr->type == PLIST_IGNORE) {
-			skip = TRUE;
-			if(Verbose && showmsg && itr->next)
-				printf("\tIgnored: %s\n", (char *)itr->next->name);
+    for (itr = pkg->head; itr != pkg->tail; itr = itr->next) {
+	if (itr->type == PLIST_CWD && skip == FALSE) {
+	    cwd = itr->name;
+	} 
+	else if (itr->type == PLIST_IGNORE) {
+	    skip = TRUE;
+	    if(Verbose && showmsg && itr->next)
+		printf("\tIgnored: %s\n", (char *)itr->next->name);
 
-			continue;
-		} 
-		else if (itr->type == PLIST_FILE && skip == FALSE) {
-			/* Save abspath of file installed in key, and pkgname in data */
-			char *entry = NULL;
-			asprintf(&entry, "%s/%s", cwd, (char *)itr->name);
+		continue;
+	} 
+	else if (itr->type == PLIST_FILE && skip == FALSE) {
+	    /* Save abspath of file installed in key, and pkgname in data */
+	    char *entry = NULL;
+	    asprintf(&entry, "%s/%s", cwd, (char *)itr->name);
 			
-			key.size = strlen(entry) + 1;
-			key.data = entry;
-			data.size = strlen(pkg->name) + 1;
-			data.data = (char *)pkg->name;
+	    key.size = strlen(entry) + 1;
+	    key.data = entry;
+	    data.size = strlen(pkg->name) + 1;
+	    data.data = (char *)pkg->name;
 
-			if(Verbose && showmsg)
-				printf("\tSaving entry %s -> %s\n", (char *)key.data, (char *)data.data);
-			dbsave(&key, &data);
-			free(entry);
-		}
-		skip = FALSE;
+	    if(Verbose && showmsg)
+		printf("\tSaving entry %s -> %s\n", (char *)key.data, 
+						    (char *)data.data);
+	    dbsave(&key, &data);
+	    free(entry);
 	}
-	return 0;
+	skip = FALSE;
+    }
+    return 0;
 }

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#11 (text+ko) ====

@@ -116,7 +116,7 @@
 #define PKG_INSTALL_VERSION	20080708
 
 #define PKG_WRAPCONF_FNAME	"/var/db/pkg_install.conf"
-#define main(argc, argv)	real_main(argc, argv)
+// #define main(argc, argv)	real_main(argc, argv)
 
 /* Version numbers to assist with changes in package file format */
 #define PLIST_FMT_VER_MAJOR	1
@@ -257,13 +257,12 @@
 int		openDatabase(int flags);
 int		dbsave(const DBT *key, const DBT *data);
 int		dbAddPackage(const char *pkgname, const char *pkgdata);
-int		dbget(const DB *db, DBT *key, DBT *data);
 char		**dbgetdata(const char *aKey);
 int		dbRemove(const char *aKey);
 Boolean		dbKeyExists(const char *aKey, DBT *data);
 Boolean		dbPackageExists(const char *portname);
 void		closeDatabase(void);
-int		dbscan(const DB *db, DBT *key, DBT *data);
+int		dbScan(DBT *key, DBT *data);
 int		cache_plist(Package *pkg, Boolean showmsg);
 
 /* Externs */

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/match.c#6 (text+ko) ====

@@ -245,85 +245,90 @@
     char **installed, **allorigins = NULL;
     char ***matches = NULL;
     int i, j;
+    Boolean CorruptPrinted = FALSE;
 
 
-	if (retval != NULL)
-		*retval = 0;
+    if (retval != NULL)
+	*retval = 0;
 
-	installed = matchinstalled(MATCH_ALL, NULL, retval);
-	if (installed == NULL)
-		return NULL;
+    installed = matchinstalled(MATCH_ALL, NULL, retval);
+    if (installed == NULL)
+	return NULL;
 
 
-	/* Gather origins for all installed packages */
-	for (i = 0; installed[i] != NULL; i++) {
-		FILE *fp;
-		char *buf, *cp, tmp[PATH_MAX];
-		int cmd;
+    /* Gather origins for all installed packages */
+    for (i = 0; installed[i] != NULL; i++) {
+	FILE *fp;
+	char *buf, *cp, tmp[PATH_MAX];
+	int cmd;
 
-		allorigins = realloc(allorigins, (i + 1) * sizeof(*allorigins));
-		allorigins[i] = NULL;
+	allorigins = realloc(allorigins, (i + 1) * sizeof(*allorigins));
+	allorigins[i] = NULL;
 
-		/*
-		 * Use the cache to lookup origin, if we don't find a key we check in
-		 * LOG_DIR and reading in the +CONTENTS file. 
-		 */
-		if (CacheExists) {
-			DBT data;
+	/*
+	 * Use the cache to lookup origin, if we don't find a key we check in
+	 * LOG_DIR and reading in the +CONTENTS file. 
+	 */
+	if (CacheExists) {
+	    DBT data;
 			
-			if(dbKeyExists(installed[i], &data)) {
-				asprintf(&buf, "%s", (char *)data.data);
-				allorigins[i] = buf;
-				continue;
-			} else {
-				if(Verbose)
-					warnx("Could not locate key %s in cache, checking in %s\n",
-						  installed[i], LOG_DIR);
-				DEBUG("matchallbyorigin(): Could not locate key\n");
-			}
+	    if(dbKeyExists(installed[i], &data)) {
+		asprintf(&buf, "%s", (char *)data.data);
+		allorigins[i] = buf;
+		continue;
+	    } else {
+		if (Verbose)
+		    warnx("Could not locate key %s in cache, checking in %s\n",
+			  installed[i], LOG_DIR);
+		if (!CorruptPrinted) {
+		    warnx("matchallbyorigin(): Your database-cache is probably corrupt; running "
+			   "pkg_convert should fix it.\n");
+		    CorruptPrinted = TRUE;
 		}
+	    }
+	}
 
-		snprintf(tmp, PATH_MAX, "%s/%s", LOG_DIR, installed[i]);
-		/*
-		 * SPECIAL CASE: ignore empty dirs, since we can can see them
-		 * during port installation.
-		 */
-		if (isemptydir(tmp))
-			continue;
+	snprintf(tmp, PATH_MAX, "%s/%s", LOG_DIR, installed[i]);
+	/*
+	 * SPECIAL CASE: ignore empty dirs, since we can can see them
+	 * during port installation.
+	 */
+	if (isemptydir(tmp))
+	    continue;
 		
-		snprintf(tmp, PATH_MAX, "%s/%s", tmp, CONTENTS_FNAME);
-		fp = fopen(tmp, "r");
-		if (fp == NULL) {
-			warnx("the package info for package '%s' is corrupt", installed[i]);
-			continue;
-		}
+	snprintf(tmp, PATH_MAX, "%s/%s", tmp, CONTENTS_FNAME);
+	fp = fopen(tmp, "r");
+	if (fp == NULL) {
+	    warnx("the package info for package '%s' is corrupt", installed[i]);
+	    continue;
+	}
 
-		cmd = -1;
-		while (fgets(tmp, sizeof(tmp), fp)) {
-			int len = strlen(tmp);
+	cmd = -1;
+	while (fgets(tmp, sizeof(tmp), fp)) {
+	    int len = strlen(tmp);
 
-			while (len && isspace(tmp[len - 1]))
-				tmp[--len] = '\0';
+	    while (len && isspace(tmp[len - 1]))
+		tmp[--len] = '\0';
 			
-			if (!len)
-				continue;
+	    if (!len)
+		continue;
 
-			cp = tmp;
-			if (tmp[0] != CMD_CHAR)
-				continue;
+	    cp = tmp;
+	    if (tmp[0] != CMD_CHAR)
+		continue;
 			
-			cmd = plist_cmd(tmp + 1, &cp);
-			if (cmd == PLIST_ORIGIN) {
-				asprintf(&buf, "%s", cp);
-				allorigins[i] = buf;
-				break;
-			}
-		}
-		if (cmd != PLIST_ORIGIN && ( Verbose || 0 != strncmp("bsdpan-", installed[i], 7 ) ) )
-			warnx("package %s has no origin recorded", installed[i]);
+	    cmd = plist_cmd(tmp + 1, &cp);
+	    if (cmd == PLIST_ORIGIN) {
+		asprintf(&buf, "%s", cp);
+		allorigins[i] = buf;
+		break;
+	    }
+	}
+	if (cmd != PLIST_ORIGIN && ( Verbose || 0 != strncmp("bsdpan-", installed[i], 7 ) ) )
+	    warnx("package %s has no origin recorded", installed[i]);
 	
-		fclose(fp);
-	}
+	fclose(fp);
+    }
 
 
     /* Resolve origins into package names, retaining the sequence */
@@ -364,14 +369,12 @@
 char **
 matchbyorigin(const char *origin, int *retval)
 {
-
     const char *origins[2];
     char ***tmp;
 
     origins[0] = origin;
     origins[1] = NULL;
 
-
     tmp = matchallbyorigin(origins, retval);
     if (tmp && tmp[0]) {
 	return tmp[0];

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#7 (text+ko) ====

@@ -430,6 +430,7 @@
     const char *Where = ".", *last_file = "";
     Boolean fail = SUCCESS;
     Boolean preserve;
+    Boolean CorruptPrinted = FALSE;
     char tmp[FILENAME_MAX], *name = NULL;
     char *prefix = NULL;
 
@@ -439,7 +440,7 @@
 	case PLIST_NAME:
 	    name = p->name;
 	    if (dbRemove(name) == -1)
-		warnx("%s: Failed to remove entry %s from db\n", __func__, name);
+		warnx("%s: Failed to remove entry %s from db", __func__, name);
 	    break;
 
 	case PLIST_IGNORE:
@@ -510,8 +511,15 @@
 		    if (delete_hierarchy(tmp, ign_err, nukedirs)) 
 			fail = FAIL;
 
-		    if (dbRemove(tmp) != 0)
-			warnx("%s: Failed to remove entry %s from db\n", __func__, tmp);
+		    if (dbRemove(tmp) != 0) {
+// 			warnx("%s: Failed to remove entry %s from db", __func__, tmp);
+			if (!CorruptPrinted) {
+			    warnx("The database-cache is probably corrupt; "
+				  "Please run pkg_convert after delete to "
+				  "fix it.");
+			    CorruptPrinted = TRUE;
+			}
+		    }
 			
 		    if (preserve && name) {
 			/* XXX: Unsure if something should be done with dbcache here? */


More information about the p4-projects mailing list