Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Jul 2008 08:07:10 GMT
From:      Anders Nore <andenore@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 145414 for review
Message-ID:  <200807180807.m6I87A5J021308@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=145414

Change 145414 by andenore@andenore_laptop on 2008/07/18 08:06:19

	Added installtime for ports and dependency fixing when installing.

Affected files ...

.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#7 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#5 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#6 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/pl.c#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/info.h#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/main.c#7 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/perform.c#7 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#4 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#5 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#9 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#5 edit

Differences ...

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

@@ -17,6 +17,8 @@
 Add:
 	- Indexes information to dbcache according to the add
 	- Added percentage progress for remote fetching ( -r option )
+	- Fixes dependencies when installing (scans installed ports, checks @pkgdep
+	  and adds matching dependency to the installing package's +REQUIRED_BY file)
 
 Delete:
 	- Deindexes information according to the delete
@@ -31,4 +33,8 @@
 
 Create:
 	- The -O option has been modified to cache information when installing ports
-	  from /usr/ports/+	  from /usr/ports/
+
+
+Packinglist:
+	- A @comment DATE:seconds-since-epoch has been added (affects add/create/info/lib)
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#5 (text+ko) ====

@@ -30,6 +30,7 @@
 #include <signal.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
+#include <time.h>
 
 static int pkg_do(char *);
 static int sanity_check(char *);
@@ -224,6 +225,9 @@
 	}
     }
 
+    /* record the installation time in CONTENTS_FNAME */
+    plist_add_installtime(&Plist);
+
     /*
      * If we have a prefix, delete the first one we see and add this
      * one in place of it.
@@ -253,7 +257,7 @@
     }
 
     /* Now check the packing list for conflicts */
-    if (!IgnoreDeps){
+    if (!IgnoreDeps) {
     for (p = Plist.head; p != NULL; p = p->next) {
 	if (p->type == PLIST_CONFLICTS) {
 	    int i;
@@ -262,18 +266,20 @@
 	    matched = matchinstalled(MATCH_GLOB, conflict, &errcode);
 	    free(conflict[0]);
 	    if (errcode == 0 && matched != NULL)
-		for (i = 0; matched[i] != NULL; i++)
+		for (i = 0; matched[i] != NULL; i++) {
 		    if (isinstalledpkg(matched[i]) > 0) {
 			warnx("package '%s' conflicts with %s", Plist.name,
 				matched[i]);
 			conflictsfound = 1;
 		    }
-
+		    free(matched[i]);
+		}
+	    free(matched);
 	    continue;
 	}
     }
-    if(conflictsfound) {
-	if(!Force) {
+    if (conflictsfound) {
+	if (!Force) {
 	    warnx("please use pkg_delete first to remove conflicting package(s) or -f to force installation");
 	    code = 1;
 	    goto bomb;
@@ -335,6 +341,7 @@
 		else if ((cp = fileGetURL(pkg, p->name, KeepPackage)) != NULL) {
 		    if (Verbose)
 			printf("Finished loading %s over FTP.\n", p->name);
+
 		    if (!fexists("+CONTENTS")) {
 			warnx("autoloaded package %s has no +CONTENTS file?",
 				p->name);
@@ -349,6 +356,7 @@
 		    }
 		    else if (Verbose)
 			printf("\t'%s' loaded successfully.\n", p->name);
+
 		    /* Nuke the temporary playpen */
 		    leave_playpen();
 		}
@@ -479,6 +487,54 @@
 	    code = 1;
 	    goto success;	/* close enough for government work */
 	}
+
+	/*
+	 * Reconstructs +REQUIRED_BY file for the package to be installed in
+	 * case it has been removed earlier (e.g. pkg_delete -f)
+	 */ 
+	if (Verbose)
+	    printf("Recording existing dependency's on %s\n", Plist.name);
+	int errcode;
+	matched = matchinstalled(MATCH_ALL, NULL, &errcode);
+	for (i = 0; matched[i] != NULL; i++) {
+	    FILE *fp;
+	    Package nplist;
+	    char path[PATH_MAX];
+
+	    /* Skip this package */
+	    if (strcmp(matched[i], Plist.name) == 0)
+		continue;
+
+	    snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, matched[i], CONTENTS_FNAME);
+	    if ((fp = fopen(path, "r")) == NULL) {
+		warn("Could not open %s for reading", path);
+		continue;
+	    }
+	    read_plist(&nplist, fp);
+	    fclose(fp);
+
+	    for (p = nplist.head; p != nplist.tail; p = p->next) {
+		if (p->type != PLIST_PKGDEP)
+		    continue;
+		if (strcmp(p->name, Plist.name) == 0) {
+		    /* Register this package in REQUIRED_BY_FNAME */
+		    snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, Plist.name, REQUIRED_BY_FNAME);
+		    if ((fp = fopen(path, "a")) == NULL) {
+			warn("Could not open %s", path);
+			continue;
+		    }
+		    fprintf(fp, "%s\n", nplist.name);
+		    fclose(fp);
+		    if (Verbose)
+			printf("\t %s depends on %s (REGISTERED)\n", p->name, Plist.name);
+		}
+	    }
+	    free_plist(&nplist);
+	    free(matched[i]);
+	}
+	free(matched);
+
+
 	/* Make sure pkg_info can read the entry */
 	vsystem("/bin/chmod a+rx %s", LogDir);
 	move_file(".", DESC_FNAME, LogDir);
@@ -515,40 +571,13 @@
 	/* make sure we've opened the database */
 	if (openDatabase(O_CREAT | O_RDWR))
 	    warn("Could not open database %s, may lead to inconsistency", DBCACHE_FILE);
-	
-	/* save package name (fast lookup in isinstalledpkg) */
-	printf("Saving package: %s Plist.name\n", Plist.name);
-	dbAddPackage(Plist.name, Plist.name); 
+	cache_plist(&Plist, Verbose); // cache information
+	closeDatabase();	
 
+	/* record dependency in the dependents +REQUIRED_BY file */
 	for (p = Plist.head; p ; p = p->next) {
-	    char *deporigin, *cwd;
-	    DBT key, data;
-	
-	    if (p->type == PLIST_CWD) {
-		cwd = p->name;
-		continue;
-	    } 
+	    char *deporigin;
 
-	    if (p->type == PLIST_FILE) {
-		/* 
-		* Save absolute path of file installed in the db-key
-		* and portname in db-data. (Makes fast -W option in pkg_info)
-		*/
-		char *entry = NULL;
-		asprintf(&entry, "%s/%s", cwd, p->name);
-		if(Verbose)
-			printf("\tSaving pair %s -> %s to db-cache\n", entry, Plist.name);
-	
-		key.size = strlen(entry) + 1;
-		key.data = entry;
-		data.size = strlen(Plist.name) + 1;
-		data.data = Plist.name;
-		dbsave(&key, &data);
-		free(entry);
-	
-		continue;
-	    }
-
 	    if (p->type != PLIST_PKGDEP)
 		continue;
 	    deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name :
@@ -663,6 +692,7 @@
 
  success:
     /* delete the packing list contents */
+	
     free_plist(&Plist);
     leave_playpen();
     return code;

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

@@ -234,24 +234,25 @@
 	add_plist_top(&plist, PLIST_COMMENT, cp);
 	free(cp);
 
-	/*
-	 * We're just here for to dump out a revised plist for the FreeBSD ports
-	 * hack.  It's not a real create in progress.
-	 * Ports uses this to fake a pkg_add installation so that we can call 
-	 * pkg_delete later.
-	 * See /usr/ports/Mk/bsd.port.mk (in the fake-pkg target)
-	 */
-	if (PlistOnly) {
-		if (openDatabase(O_CREAT | O_RDWR))
-			err("Could not open database: %s", DBCACHE_FILE);
+    /*
+     * We're just here for to dump out a revised plist for the FreeBSD ports
+     * hack.  It's not a real create in progress.
+     * Ports uses this to fake a pkg_add installation so that we can call 
+     * pkg_delete later.
+     * See /usr/ports/Mk/bsd.port.mk (in the fake-pkg target)
+     */
+    if (PlistOnly) {
+	if (openDatabase(O_CREAT | O_RDWR))
+	    err("Could not open database: %s", DBCACHE_FILE);
 	
-		check_list(home, &plist);
-		write_plist(&plist, stdout);
-		int retval = cache_plist(&plist, FALSE);
+	plist_add_installtime(&plist);
+	check_list(home, &plist);	
+	write_plist(&plist, stdout);
+	int retval = cache_plist(&plist, FALSE);
 
-		closeDatabase();
-		exit(retval);
-	}
+	closeDatabase();
+	exit(retval);
+    }
 
     /* Make a directory to stomp around in */
     home = make_playpen(PlayPen, 0);

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/pl.c#3 (text+ko) ====

@@ -63,40 +63,40 @@
 void
 check_list(const char *home, Package *pkg)
 {
-	const char *where = home;
-	const char *there = NULL;
-	char name[FILENAME_MAX];
-	char *prefix = NULL;
-	PackingList p;
+    const char *where = home;
+    const char *there = NULL;
+    char name[FILENAME_MAX];
+    char *prefix = NULL;
+    PackingList p;
 
-	for (p = pkg->head; p != NULL; p = p->next)
-	switch (p->type) {
-	case PLIST_CWD:
-		if (!prefix)
-			prefix = p->name;
-		where = (p->name == NULL) ? prefix : p->name;
-		break;
+    for (p = pkg->head; p != NULL; p = p->next)
+    switch (p->type) {
+    case PLIST_CWD:
+	if (!prefix)
+	    prefix = p->name;
+	where = (p->name == NULL) ? prefix : p->name;
+	break;
 
-	case PLIST_IGNORE:
-		p = p->next;
-		break;
+    case PLIST_IGNORE:
+	p = p->next;
+	break;
 
-	case PLIST_SRC:
-		there = p->name;
-		break;
+    case PLIST_SRC:
+	there = p->name;
+	break;
 
-	case PLIST_FILE:
-		if (there)
-			snprintf(name, sizeof(name), "%s/%s", there, p->name);
-		else
-			snprintf(name, sizeof(name), "%s%s/%s",
-			BaseDir && where && where[0] == '/' ? BaseDir : "", where, p->name);
+    case PLIST_FILE:
+	if (there)
+	    snprintf(name, sizeof(name), "%s/%s", there, p->name);
+	else
+	    snprintf(name, sizeof(name), "%s%s/%s",
+	    BaseDir && where && where[0] == '/' ? BaseDir : "", where, p->name);
 
-		add_cksum(pkg, p, name);
-		break;
-	default:
-		break;
-	}
+	    add_cksum(pkg, p, name);
+	    break;
+    default:
+	break;
+    }
 }
 
 static int

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

@@ -52,6 +52,7 @@
 #define SHOW_PTREV	0x10000
 #define SHOW_DEPEND	0x20000
 #define SHOW_PKGNAME	0x40000
+#define SHOW_DATE	0x80000
 
 struct which_entry {
     TAILQ_ENTRY(which_entry) next;
@@ -80,5 +81,6 @@
 extern void	show_cksum(const char *, Package *);
 extern void	show_origin(const char *, Package *);
 extern void	show_fmtrev(const char *, Package *);
+extern void 	show_date(const char *, Package *);
 
 #endif	/* _INST_INFO_H_INCLUDE */

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

@@ -41,7 +41,7 @@
 
 static void usage(void);
 
-static char opts[] = "abcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:vVW:xX";
+static char opts[] = "abcdDe:EfgGhiIjkKl:LmoO:pPqQrRst:TvVW:xX";
 static struct option longopts[] = {
 	{ "all",	no_argument,		NULL,		'a' },
 	{ "blocksize",	no_argument,		NULL,		'b' },
@@ -57,6 +57,7 @@
 	{ "template",	required_argument,	NULL,		't' },
 	{ "verbose",	no_argument,		NULL,		'v' },
 	{ "version",	no_argument,		NULL,		'P' },
+	{ "time",	no_argument,		NULL,		'T' },
 	{ "which",	required_argument,	NULL,		'W' },
 };
 
@@ -88,7 +89,7 @@
 	switch(ch) {
 	case 'a':
 	    MatchType = MATCH_ALL;
-
+	    break;
 	case 'v':
 	    Verbose++;
 	    /* Reasonable definition of 'everything' */
@@ -199,6 +200,9 @@
 	    strlcpy(PlayPen, optarg, sizeof(PlayPen));
 	    break;
 
+	case 'T':
+	    Flags |= SHOW_DATE;
+
 	case 'x':
 	    MatchType = MATCH_REGEX;
 	    break;
@@ -288,12 +292,12 @@
 static void
 usage()
 {
-	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
-	"usage: pkg_info [-bcdDEfgGiIjkKLmopPqQrRsvVxX] [-e package] [-l prefix]",
-	"                [-t template] -a | pkg-name ...",
-	"       pkg_info [-qQ] -W filename",
-	"       pkg_info [-qQ] -O origin",
-	"       pkg_info");
+    fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
+    "usage: pkg_info [-bcdDEfgGiIjkKLmopPqQrRsTvVxX] [-e package] [-l prefix]",
+    "                [-t template] -a | pkg-name ...",
+    "       pkg_info [-qQ] -W filename",
+    "       pkg_info [-qQ] -O origin",
+    "       pkg_info");
     exit(1);
 }
 

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

@@ -169,7 +169,7 @@
 	/* We don't want to read the packinglist if not necessary (it's slow) */
 	if (Flags & SHOW_DEPEND || Flags & SHOW_PLIST || Flags & SHOW_PREFIX || 
 		Flags & SHOW_FILES || Flags & SHOW_SIZE || Flags & SHOW_CKSUM || 
-		Flags & SHOW_ORIGIN || Flags & SHOW_FMTREV) {
+		Flags & SHOW_ORIGIN || Flags & SHOW_FMTREV || Flags & SHOW_DATE) {
 
 		/* Suck in the contents list */		
 		fp = fopen(CONTENTS_FNAME, "r");
@@ -187,55 +187,57 @@
      * Index is special info type that has to override all others to make
      * any sense (this is the default behaviour of pkg_info).
      */
-	if (Flags & SHOW_INDEX) {
-		char tmp[FILENAME_MAX];
-		snprintf(tmp, FILENAME_MAX, "%-19s ", pkg);
-		show_index(tmp, COMMENT_FNAME);
-	}
-	else {
+    if (Flags & SHOW_INDEX) {
+	char tmp[FILENAME_MAX];
+	snprintf(tmp, FILENAME_MAX, "%-19s ", pkg);
+	show_index(tmp, COMMENT_FNAME);
+    }
+    else {
 	/* Start showing the package contents */
 	if (!Quiet)
-		printf("%sInformation for %s:\n\n", InfoPrefix, pkg);
+	    printf("%sInformation for %s:\n\n", InfoPrefix, pkg);
 	else if (QUIET)
-		printf("%s%s:", InfoPrefix, pkg);
+	    printf("%s%s:", InfoPrefix, pkg);
 	if (Flags & SHOW_COMMENT)
-		show_file("Comment:\n", COMMENT_FNAME);
+	    show_file("Comment:\n", COMMENT_FNAME);
 	if (Flags & SHOW_DEPEND)
-		show_plist("Depends on:\n", &plist, PLIST_PKGDEP, FALSE);
+	    show_plist("Depends on:\n", &plist, PLIST_PKGDEP, FALSE);
 	if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME))
-		show_file("Required by:\n", REQUIRED_BY_FNAME);
+	    show_file("Required by:\n", REQUIRED_BY_FNAME);
 	if (Flags & SHOW_DESC)
-		show_file("Description:\n", DESC_FNAME);
+	    show_file("Description:\n", DESC_FNAME);
 	if ((Flags & SHOW_DISPLAY) && fexists(DISPLAY_FNAME))
-		show_file("Install notice:\n", DISPLAY_FNAME);
+	    show_file("Install notice:\n", DISPLAY_FNAME);
 	if (Flags & SHOW_PLIST)
-		show_plist("Packing list:\n", &plist, (plist_t)0, TRUE);
+	    show_plist("Packing list:\n", &plist, (plist_t)0, TRUE);
 	if (Flags & SHOW_REQUIRE && fexists(REQUIRE_FNAME))
-		show_file("Requirements script:\n", REQUIRE_FNAME);
+	    show_file("Requirements script:\n", REQUIRE_FNAME);
 	if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME))
-		show_file("Install script:\n", INSTALL_FNAME);
+	    show_file("Install script:\n", INSTALL_FNAME);
 	if ((Flags & SHOW_INSTALL) && fexists(POST_INSTALL_FNAME))
-		show_file("Post-Install script:\n", POST_INSTALL_FNAME);
+	    show_file("Post-Install script:\n", POST_INSTALL_FNAME);
 	if ((Flags & SHOW_DEINSTALL) && fexists(DEINSTALL_FNAME))
-		show_file("De-Install script:\n", DEINSTALL_FNAME);
+	    show_file("De-Install script:\n", DEINSTALL_FNAME);
 	if ((Flags & SHOW_DEINSTALL) && fexists(POST_DEINSTALL_FNAME))
-		show_file("Post-DeInstall script:\n", POST_DEINSTALL_FNAME);
+	    show_file("Post-DeInstall script:\n", POST_DEINSTALL_FNAME);
 	if ((Flags & SHOW_MTREE) && fexists(MTREE_FNAME))
-		show_file("mtree file:\n", MTREE_FNAME);
+	    show_file("mtree file:\n", MTREE_FNAME);
 	if (Flags & SHOW_PREFIX)
-		show_plist("Prefix(s):\n", &plist, PLIST_CWD, FALSE);
+	    show_plist("Prefix(s):\n", &plist, PLIST_CWD, FALSE);
 	if (Flags & SHOW_FILES)
-		show_files("Files:\n", &plist);
+	    show_files("Files:\n", &plist);
 	if ((Flags & SHOW_SIZE) && installed)
-		show_size("Package Size:\n", &plist);
+	    show_size("Package Size:\n", &plist);
 	if ((Flags & SHOW_CKSUM) && installed)
-		show_cksum("Mismatched Checksums:\n", &plist);
+	    show_cksum("Mismatched Checksums:\n", &plist);
 	if (Flags & SHOW_ORIGIN)
-		show_origin("Origin:\n", &plist);
+	    show_origin("Origin:\n", &plist);
 	if (Flags & SHOW_FMTREV)
-		show_fmtrev("Packing list format revision:\n", &plist);
+	    show_fmtrev("Packing list format revision:\n", &plist);
+	if (Flags & SHOW_DATE)
+	    show_date("Installation date:\n", &plist);
 	if (!Quiet)
-		puts(InfoPrefix);
+	    puts(InfoPrefix);
     }
 
 	if(plist.head != NULL && plist.tail != NULL)

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

@@ -143,6 +143,8 @@
 .Fx
 .Em "Ports Collection"
 of the underlying port from which the package was generated.
+.It Fl T
+Shows the time and date of installation
 .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#5 (text+ko) ====

@@ -390,7 +390,6 @@
 void
 show_origin(const char *title, Package *plist)
 {
-
     if (!Quiet)
 	printf("%s%s", InfoPrefix, title);
     printf("%s\n", plist->origin != NULL ? plist->origin : "");
@@ -400,8 +399,19 @@
 void
 show_fmtrev(const char *title, Package *plist)
 {
+    if (!Quiet)
+	printf("%s%s", InfoPrefix, title);
+    printf("%d.%d\n", plist->fmtver_maj, plist->fmtver_mnr);
+}
 
+void
+show_date(const char *title, Package *plist)
+{
+    time_t datetime = (time_t)plist->datetime;
     if (!Quiet)
 	printf("%s%s", InfoPrefix, title);
-    printf("%d.%d\n", plist->fmtver_maj, plist->fmtver_mnr);
+
+    printf("%s\n", datetime ? ctime(&datetime) : "No recorded installation time");
+
 }
+

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

@@ -154,7 +154,7 @@
     struct _plist *head, *tail;
     const char *name;
     const char *origin;
-    int fmtver_maj, fmtver_mnr;
+    int fmtver_maj, fmtver_mnr, datetime;
 };
 typedef struct _pack Package;
 
@@ -229,6 +229,7 @@
 int		plist_cmd(const char *, char **);
 int		delete_package(Boolean, Boolean, Package *);
 Boolean 	make_preserve_name(char *, int, const char *, const char *);
+void		plist_add_installtime(Package *);
 
 /* For all */
 int		pkg_perform(char **);

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

@@ -191,71 +191,71 @@
 int
 plist_cmd(const char *s, char **arg)
 {
-	char cmd[FILENAME_MAX + 20];	/* 20 == fudge for max cmd len */
-	char *cp;
-	const char *sp;
+    char cmd[FILENAME_MAX + 20];	/* 20 == fudge for max cmd len */
+    char *cp;
+    const char *sp;
 
-	strcpy(cmd, s);
-	str_lowercase(cmd);
-	cp = cmd;
-	sp = s;
-	while (*cp) {
-		if (isspace(*cp)) {
-			*cp = '\0';
-			while (isspace(*sp)) /* Never sure if macro, increment later */
-				++sp;
-			break;
-		}
+    strcpy(cmd, s);
+    str_lowercase(cmd);
+    cp = cmd;
+    sp = s;
+    while (*cp) {
+	if (isspace(*cp)) {
+	    *cp = '\0';
+	    while (isspace(*sp)) /* Never sure if macro, increment later */
+		++sp;
+		break;
+	    }
 	++cp, ++sp;
-	}
-	if (arg)
-	*arg = (char *)sp;
-	if (!strcmp(cmd, "cwd"))
+    }
+    if (arg)
+    *arg = (char *)sp;
+    if (!strcmp(cmd, "cwd"))
 	return PLIST_CWD;
-	else if (!strcmp(cmd, "srcdir"))
+    else if (!strcmp(cmd, "srcdir"))
 	return PLIST_SRC;
-	else if (!strcmp(cmd, "cd"))
+    else if (!strcmp(cmd, "cd"))
 	return PLIST_CWD;
-	else if (!strcmp(cmd, "exec"))
+    else if (!strcmp(cmd, "exec"))
 	return PLIST_CMD;
-	else if (!strcmp(cmd, "unexec"))
+    else if (!strcmp(cmd, "unexec"))
 	return PLIST_UNEXEC;
-	else if (!strcmp(cmd, "mode"))
+    else if (!strcmp(cmd, "mode"))
 	return PLIST_CHMOD;
-	else if (!strcmp(cmd, "owner"))
+    else if (!strcmp(cmd, "owner"))
 	return PLIST_CHOWN;
-	else if (!strcmp(cmd, "group"))
+    else if (!strcmp(cmd, "group"))
 	return PLIST_CHGRP;
-	else if (!strcmp(cmd, "noinst"))
+    else if (!strcmp(cmd, "noinst"))
 	return PLIST_NOINST;
-	else if (!strcmp(cmd, "comment")) {
+    else if (!strcmp(cmd, "comment")) {
 	if (!strncmp(*arg, "ORIGIN:", 7)) {
-		*arg += 7;
-		return PLIST_ORIGIN;
+	    *arg += 7;
+	    return PLIST_ORIGIN;
 	} else if (!strncmp(*arg, "DEPORIGIN:", 10)) {
-		*arg += 10;
-		return PLIST_DEPORIGIN;
+	    *arg += 10;
+	    return PLIST_DEPORIGIN;
 	}
 	return PLIST_COMMENT;
-	} else if (!strcmp(cmd, "ignore"))
+    } else if (!strcmp(cmd, "ignore"))
 	return PLIST_IGNORE;
-	else if (!strcmp(cmd, "ignore_inst"))
+    else if (!strcmp(cmd, "ignore_inst"))
 	return PLIST_IGNORE_INST;
-	else if (!strcmp(cmd, "name"))
+    else if (!strcmp(cmd, "name"))
 	return PLIST_NAME;
-	else if (!strcmp(cmd, "display"))
+    else if (!strcmp(cmd, "display"))
 	return PLIST_DISPLAY;
-	else if (!strcmp(cmd, "pkgdep"))
+    else if (!strcmp(cmd, "pkgdep"))
 	return PLIST_PKGDEP;
-	else if (!strcmp(cmd, "conflicts"))
+    else if (!strcmp(cmd, "conflicts"))
 	return PLIST_CONFLICTS;
-	else if (!strcmp(cmd, "mtree"))
+    else if (!strcmp(cmd, "mtree"))
 	return PLIST_MTREE;
-	else if (!strcmp(cmd, "dirrm"))
+    else if (!strcmp(cmd, "dirrm"))
 	return PLIST_DIR_RM;
-	else if (!strcmp(cmd, "option"))
+    else if (!strcmp(cmd, "option"))
 	return PLIST_OPTION;
-	else
+    else
 	return FAIL;
 }
 
@@ -263,153 +263,157 @@
 void
 read_plist(Package *pkg, FILE *fp)
 {
-	char *cp, pline[FILENAME_MAX];
-	int cmd, major, minor;
+    char *cp, pline[FILENAME_MAX];
+    int cmd, major, minor, date;
 
-	pkg->fmtver_maj = 1;
-	pkg->fmtver_mnr = 0;
-	pkg->origin = NULL;
-	while (fgets(pline, FILENAME_MAX, fp)) {
-		int len = strlen(pline);
+    pkg->fmtver_maj = 1;
+    pkg->fmtver_mnr = 0;
+    pkg->datetime = 0;
+    pkg->origin = NULL;
+    while (fgets(pline, FILENAME_MAX, fp)) {
+	int len = strlen(pline);
 	
-		while (len && isspace(pline[len - 1]))
-			pline[--len] = '\0';
+	while (len && isspace(pline[len - 1]))
+	    pline[--len] = '\0';
 	
-		if (!len)
-			continue;
-		cp = pline;
-		if (pline[0] != CMD_CHAR) {
-			cmd = PLIST_FILE;
-			goto bottom;
-		}
-		cmd = plist_cmd(pline + 1, &cp);
-		if (cmd == FAIL) {
-			warnx("%s: unknown command '%s' (package tools out of date?)",
-			__func__, pline);
-			goto bottom;
-		}
-		if (*cp == '\0') {
-			cp = NULL;
-			goto bottom;
-		}
-		if (cmd == PLIST_COMMENT && sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n",
-							&major, &minor) == 2) {
-			pkg->fmtver_maj = major;
-			pkg->fmtver_mnr = minor;
-			if (verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR) <= 0)
-			goto bottom;
+	if (!len)
+	    continue;
+	cp = pline;
+	if (pline[0] != CMD_CHAR) {
+	    cmd = PLIST_FILE;
+	    goto bottom;
+	}
+	cmd = plist_cmd(pline + 1, &cp);
+	if (cmd == FAIL) {
+	    warnx("%s: unknown command '%s' (package tools out of date?)",
+		__func__, pline);
+		goto bottom;
+	}
+	if (*cp == '\0') {
+	    cp = NULL;
+	    goto bottom;
+	}
+	if (cmd == PLIST_COMMENT && sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n",
+						&major, &minor) == 2) {
+	    pkg->fmtver_maj = major;
+	    pkg->fmtver_mnr = minor;
+	    if (verscmp(pkg, PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR) <= 0)
+	    goto bottom;
 	
-			warnx("plist format revision (%d.%d) is higher than supported"
-			"(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr,
+	    warnx("plist format revision (%d.%d) is higher than supported"
+		  "(%d.%d)", pkg->fmtver_maj, pkg->fmtver_mnr,
 			PLIST_FMT_VER_MAJOR, PLIST_FMT_VER_MINOR);
-			if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) {
-			cleanup(0);
-			exit(2);
-			}
-		}
+	    if (pkg->fmtver_maj > PLIST_FMT_VER_MAJOR) {
+		cleanup(0);
+		exit(2);
+	    }
+	}
+	if (cmd == PLIST_COMMENT && sscanf(cp, "DATE:%d\n", &date) == 1) {
+	    pkg->datetime = date;
+	}
 	
 	bottom:
 		add_plist(pkg, cmd, cp);
-	}
+    }
 }
 
 /* Write a packing list to a file, converting commands to ascii equivs */
 void
 write_plist(Package *pkg, FILE *fp)
 {
-	PackingList plist = pkg->head;
+    PackingList plist = pkg->head;
 
-	while (plist) {
+    while (plist) {
 	switch(plist->type) {
 	case PLIST_FILE:
-		fprintf(fp, "%s\n", plist->name);
-		break;
+	    fprintf(fp, "%s\n", plist->name);
+	    break;
 
 	case PLIST_CWD:
-		fprintf(fp, "%ccwd %s\n", CMD_CHAR, (plist->name == NULL) ? "" : plist->name);
-		break;
+	    fprintf(fp, "%ccwd %s\n", CMD_CHAR, (plist->name == NULL) ? "" : plist->name);
+	    break;
 
 	case PLIST_SRC:
-		fprintf(fp, "%csrcdir %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%csrcdir %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_CMD:
-		fprintf(fp, "%cexec %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%cexec %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_UNEXEC:
-		fprintf(fp, "%cunexec %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%cunexec %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_CHMOD:
-		fprintf(fp, "%cmode %s\n", CMD_CHAR, plist->name ? plist->name : "");
-		break;
+	    fprintf(fp, "%cmode %s\n", CMD_CHAR, plist->name ? plist->name : "");
+	    break;
 
 	case PLIST_CHOWN:
-		fprintf(fp, "%cowner %s\n", CMD_CHAR, plist->name ? plist->name : "");
-		break;
+	    fprintf(fp, "%cowner %s\n", CMD_CHAR, plist->name ? plist->name : "");
+	    break;
 
 	case PLIST_CHGRP:
-		fprintf(fp, "%cgroup %s\n", CMD_CHAR, plist->name ? plist->name : "");
-		break;
+	    fprintf(fp, "%cgroup %s\n", CMD_CHAR, plist->name ? plist->name : "");
+	    break;
 
 	case PLIST_COMMENT:
-		fprintf(fp, "%ccomment %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%ccomment %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_NOINST:
-		fprintf(fp, "%cnoinst %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%cnoinst %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_IGNORE:
 	case PLIST_IGNORE_INST:		/* a one-time non-ignored file */
-		fprintf(fp, "%cignore\n", CMD_CHAR);
-		break;
+	    fprintf(fp, "%cignore\n", CMD_CHAR);
+	    break;
 
 	case PLIST_NAME:
-		fprintf(fp, "%cname %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%cname %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_DISPLAY:
-		fprintf(fp, "%cdisplay %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%cdisplay %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_PKGDEP:
-		fprintf(fp, "%cpkgdep %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%cpkgdep %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_CONFLICTS:
-		fprintf(fp, "%cconflicts %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%cconflicts %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_MTREE:
-		fprintf(fp, "%cmtree %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%cmtree %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_DIR_RM:
-		fprintf(fp, "%cdirrm %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%cdirrm %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_OPTION:
-		fprintf(fp, "%coption %s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%coption %s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_ORIGIN:
-		fprintf(fp, "%ccomment ORIGIN:%s\n", CMD_CHAR, plist->name);
-		break;
+	    fprintf(fp, "%ccomment ORIGIN:%s\n", CMD_CHAR, plist->name);
+	    break;
 
 	case PLIST_DEPORIGIN:
-		fprintf(fp, "%ccomment DEPORIGIN:%s\n", CMD_CHAR, plist->name);
-		break;
-
+	    fprintf(fp, "%ccomment DEPORIGIN:%s\n", CMD_CHAR, plist->name);
+	    break;
+	
 	default:
-		cleanup(0);
-		errx(2, "%s: unknown command type %d (%s)", __func__,
-		plist->type, plist->name);
-		break;
+	    cleanup(0);
+	    errx(2, "%s: unknown command type %d (%s)", __func__,
+	    plist->type, plist->name);
+	    break;
 	}
 	plist = plist->next;
-	}
+    }
 }
 
 /*
@@ -421,132 +425,131 @@
 int
 delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
 {
-	PackingList p;
-	const char *Where = ".", *last_file = "";
-	Boolean fail = SUCCESS;
-	Boolean preserve;
-	char tmp[FILENAME_MAX], *name = NULL;
-	char *prefix = NULL;
+    PackingList p;
+    const char *Where = ".", *last_file = "";
+    Boolean fail = SUCCESS;
+    Boolean preserve;
+    char tmp[FILENAME_MAX], *name = NULL;
+    char *prefix = NULL;
 
-	preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
-	for (p = pkg->head; p; p = p->next) {
+    preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
+    for (p = pkg->head; p; p = p->next) {
 	switch (p->type)  {
 	case PLIST_NAME:
-		name = p->name;
-		if (dbRemove(name) != 0)
-			warnx("%s: Failed to remove entry %s from db\n", __func__, name);
-		
-		break;
+	    name = p->name;
+	    if (dbRemove(name) != 0)
+		warnx("%s: Failed to remove entry %s from db\n", __func__, name);
+	    break;
 
 	case PLIST_IGNORE:
-		p = p->next;
-		break;
+	    p = p->next;
+	    break;
 
 	case PLIST_CWD:
-		if (!prefix)
-			prefix = p->name;
+	    if (!prefix)
+		prefix = p->name;
 		
-		Where = (p->name == NULL) ? prefix : p->name;
+	    Where = (p->name == NULL) ? prefix : p->name;
 		
-		if (Verbose)
-			printf("Change working directory to %s\n", Where);
-		break;
+	    if (Verbose)
+		printf("Change working directory to %s\n", Where);
+	    break;
 
 	case PLIST_UNEXEC:
-		format_cmd(tmp, FILENAME_MAX, p->name, Where, last_file);
-		if (Verbose)
-			printf("Execute '%s'\n", tmp);
-		if (!Fake && system(tmp)) {
-			warnx("unexec command for '%s' failed", tmp);
-			fail = FAIL;
-		}
-		break;
+	    format_cmd(tmp, FILENAME_MAX, p->name, Where, last_file);

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807180807.m6I87A5J021308>