Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Aug 2008 19:13:53 GMT
From:      Anders Nore <andenore@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 146646 for review
Message-ID:  <200808041913.m74JDrKl033613@repoman.freebsd.org>

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

Change 146646 by andenore@andenore_laptop on 2008/08/04 19:13:38

	pkg_delete has a new option -M, that deletes packages within installtimes.
	pkg_delete -M '*>=2008 07 14<2008 08'

Affected files ...

.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#10 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/delete.h#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/main.c#5 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/perform.c#5 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/info.h#6 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/perform.c#9 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#8 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#10 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/date.c#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#13 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/match.c#8 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#8 edit

Differences ...

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

@@ -1,10 +1,11 @@
 Changes made to pkg_install during SoC2008 by Anders Nore (andenore@FreeBSD.org)
-Last modified: 2008 07 21
+Last modified: 2008 08 03
 
 
 Converter: 
 	- Added convert program that indexes information to PKG_DBCACHE_FILE
 	- Added some features to lookup keys and print them (or print whole db)
+	- Caches origin, installtime and which-files (files in package to pkgname)
 
 Info:
 	- Improved performance for -W option using the dbcache
@@ -14,6 +15,9 @@
 	- 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)
 	- Print installation date with -n (human readable) or -N (seconds since epoch)
+	- Added installtime comparison with the -M option, e.g,
+	  "pkg_info -M '*>2008 07 18'" will list all packages installed after
+	  the date YYYY MM DD.
 
 Add:
 	- Indexes information to dbcache according to the add
@@ -23,6 +27,10 @@
 
 Delete:
 	- Deindexes information according to the delete
+	- Now supports range deletion with installdates, e.g.,
+	  pkg_delete -i -M '*>=2008 07 14<2008 08' will delete all packages
+	  installed between dates 2008 07 14 and 2008 08, asking for y/n before
+	  the deletion.
 
 Lib:
 	- Changed methods in match.c to use cache if available (matchallbyorigin, ispkginstalled)
@@ -31,6 +39,7 @@
 	- Added function to cache a Packagelist (cache_plist())
 	- The environment variable PKG_DBCAHE_FILE can be set to make the file
 	  location different than the default /var/db/pkg/pkgcache.db
+	- pattern_match will compare dates as well as version numbers.
 
 Create:
 	- The -O option has been modified to cache information when installing ports

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

@@ -31,5 +31,6 @@
 extern char	*Directory;
 extern char	*PkgName;
 extern match_t	MatchType;
+extern Boolean  DateMatch;
 
 #endif	/* _INST_DELETE_H_INCLUDE */

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

@@ -26,6 +26,7 @@
 #include <sys/stat.h>
 #include <getopt.h>
 #include <err.h>
+#include <sys/errno.h>
 
 #include "lib.h"
 #include "delete.h"
@@ -35,11 +36,12 @@
 Boolean	Interactive	= FALSE;
 Boolean	NoDeInstall	= FALSE;
 Boolean	Recursive	= FALSE;
+Boolean DateMatch	= FALSE;
 match_t	MatchType	= MATCH_GLOB;
 
 static void usage(void);
 
-static char opts[] = "adDfGhinp:rvxX";
+static char opts[] = "adDfGhiMnp:rvxX";
 static struct option longopts[] = {
 	{ "all",	no_argument,		NULL,		'a' },
 	{ "clean-dirs",	no_argument,		NULL,		'd' },
@@ -67,11 +69,6 @@
     const char *tmp;
     struct stat stat_s;
 
-	if(cacheExists()) {
-		openDatabase(O_RDWR);
-		atexit(closeDatabase);
-	}
-
     pkgs = start = argv;
     while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1)
 	switch(ch) {
@@ -116,6 +113,10 @@
 	    MatchType = MATCH_EREGEX;
 	    break;
 
+	case 'M':
+	    DateMatch = TRUE;
+	    break;
+
 	case 'i':
 	    Interactive = TRUE;
 	    break;
@@ -153,6 +154,19 @@
 	*pkgs++ = *argv++;
     }
 
+    if(cacheExists()) {
+	openDatabase(O_RDWR);
+	if (errno == EACCES)
+	    if (openDatabase(O_RDONLY))
+		warn("Could not open database");
+	    else {
+		warnx("you do not own dbcache: %s %s",
+		     DBCACHE_FILE, Force ? "(proceeding anyways)" : "");
+	    }
+
+	atexit(closeDatabase);
+    }
+
     /* If no packages, yelp */
     if (pkgs == start && MatchType != MATCH_ALL)
 	warnx("missing package name(s)"), usage();

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

@@ -34,43 +34,43 @@
 int
 pkg_perform(char **pkgs)
 {
-	char **matched, **rb, **rbtmp;
-	int errcode, i, j;
-	int err_cnt = 0;
-	struct reqr_by_entry *rb_entry;
-	struct reqr_by_head *rb_list;
+    char **matched, **rb, **rbtmp;
+    int errcode, i, j;
+    int err_cnt = 0;
+    struct reqr_by_entry *rb_entry;
+    struct reqr_by_head *rb_list;
 
-	if (MatchType != MATCH_EXACT) {
-		matched = matchinstalled(MatchType, pkgs, &errcode);
-		if (errcode != 0)
-			return 1;
+    if (MatchType != MATCH_EXACT) {
+	matched = matchinstalled(MatchType * (DateMatch ? 10 : 1), pkgs, &errcode);
+	if (errcode != 0)
+	    return 1;
 
-		/*
-		* Copy matched[] into pkgs[], because we'll need to use
-		* matchinstalled() later on.
-		*/
-		if (matched != NULL) {
-			pkgs = NULL;
-			for (i = 0; matched[i] != NULL; i++) {
-				pkgs = realloc(pkgs, sizeof(*pkgs) * (i + 2));
-				pkgs[i] = strdup(matched[i]);
-			}
-			pkgs[i] = NULL;
-		}
-		else switch (MatchType) {
-			case MATCH_GLOB:
-				break;
-			case MATCH_ALL:
-				warnx("no packages installed");
-				return 0;
-			case MATCH_EREGEX:
-			case MATCH_REGEX:
-				warnx("no packages match pattern(s)");
-				return 1;
-			default:
-				break;
-		}
+	/*
+	* Copy matched[] into pkgs[], because we'll need to use
+	* matchinstalled() later on.
+	*/
+	if (matched != NULL) {
+	    pkgs = NULL;
+	    for (i = 0; matched[i] != NULL; i++) {
+		pkgs = realloc(pkgs, sizeof(*pkgs) * (i + 2));
+		pkgs[i] = strdup(matched[i]);
+	    }
+	    pkgs[i] = NULL;
+	}
+	else switch (MatchType) {
+	    case MATCH_GLOB:
+		break;
+	    case MATCH_ALL:
+		warnx("no packages installed");
+		return 0;
+	    case MATCH_EREGEX:
+	    case MATCH_REGEX:
+		warnx("no packages match pattern(s)");
+		return 1;
+	    default:
+		break;
 	}
+    }
 
 	err_cnt += sortdeps(pkgs);
 	for (i = 0; pkgs[i]; i++) {

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

@@ -83,6 +83,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 *);
+extern void 	show_date(const char *, const char *);
 
 #endif	/* _INST_INFO_H_INCLUDE */

==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/perform.c#9 (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_DATE) {
+	Flags & SHOW_ORIGIN || Flags & SHOW_FMTREV) {
 
 	/* Suck in the contents list */		
 	fp = fopen(CONTENTS_FNAME, "r");
@@ -235,7 +235,7 @@
 	if (Flags & SHOW_FMTREV)
 	    show_fmtrev("Packing list format revision:\n", &plist);
 	if (Flags & SHOW_DATE)
-	    show_date("Installation date:\n", &plist);
+	    show_date("Installation date:\n", pkg);
 	if (!Quiet)
 	    puts(InfoPrefix);
     }

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

@@ -389,10 +389,11 @@
     printf("%d.%d\n", plist->fmtver_maj, plist->fmtver_mnr);
 }
 
+/* Show the installation date and time of pkgname */
 void
-show_date(const char *title, Package *plist)
+show_date(const char *title, const char *pkgname)
 {
-    time_t datetime = (time_t)plist->datetime;
+    time_t datetime = getInstallDate(pkgname);
     if (!Quiet)
 	printf("%s%s", InfoPrefix, title);
 
@@ -403,6 +404,6 @@
 	    printf("%s\n", ctime(&datetime));
     }
     else
-	printf("No recorder installation time\n");
+	printf("No recorded installation time\n");
 }
 

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

@@ -61,7 +61,7 @@
 // 	DEBUG("openDatabase()\n");
     if (database == NULL) {
 	database = opendb(DBCACHE_FILE, flags);
-	if (database)
+	if (database != NULL)
 	    CacheExists = TRUE;
     } 
 
@@ -282,10 +282,10 @@
 	etime = pkg->datetime;
     else {
 	char path[PATH_MAX];
-	snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, pkg->name, CONTENTS_FNAME);
+	snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, pkg->name, COMMENT_FNAME);
 	if (stat(path, &fstat) == -1)
 	    warn("Cannot stat file: %s", path);
-	etime = fstat.st_mtime;
+	etime = fstat.st_ctime;
     }
 
     char *tmp[128], tmp2[128];

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

@@ -7,8 +7,9 @@
     int result = 0;
     char path[PATH_MAX];
     FILE *fp;
-    Package package;
+    Package plist;
 
+    bzero(&plist, sizeof(plist));
     if (CacheExists) {
 	char key[1024];
 	DBT data;
@@ -18,20 +19,23 @@
 	    if(sscanf(data.data, "%d", &result) == 0) {
 		warnx("getInstallDate: Database may be corrupt");
 		return -1;
-	    } else
+	    } else {
 		return result;
+	    }
 	}
     }
 
     /* If we don't have cache or the key don't exist (reading plist = SLOW) */
     snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, pkgname, CONTENTS_FNAME);
+
     fp = fopen(path, "r");
-    if (!fp)
+    if (!fp) {
 	warn("Could not open %s", path);
+	return 0;
+    }
+    read_plist(&plist, fp);
 
-    read_plist(&package, fp);
-
-    return package.datetime;
+    return plist.datetime;
 }
 
 int
@@ -50,21 +54,23 @@
 }
 
 int
-date_cmp(char *pkgname, char *date)
+date_cmp(const char *pkgname, const char *date)
 {
     unsigned int year = 0;
     unsigned int month = 0;
     unsigned int day = 0;
+
     if ((sscanf(date, "%u %u %u", &year, &month, &day) == 0))
 	warnx("Invalid date format: %s", date);
 
     int time1 = getInstallDate(pkgname);
     int time2 = getTime(year, month, day);
 
-    if (time1 > time2)
+    if (time1 > time2) {
 	return 1;
-    else if (time1 == time2)
+    } else if (time1 == time2) {
 	return 0;
-    else
+    } else {
 	return -1;
+    }
 }
==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#13 (text+ko) ====

@@ -268,9 +268,9 @@
 int		cache_plist(Package *pkg, Boolean showmsg);
 
 /* Date */
-int getInstallDate(const char *pkgname);
-int getTime(int year, int month, int day);
-int date_cmp(char *pkgname, char *date);
+int		getInstallDate(const char *pkgname);
+int		getTime(int year, int month, int day);
+int		date_cmp(const char *pkgname, const char *date);
 
 /* Externs */
 extern Boolean	Quiet;

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

@@ -43,7 +43,6 @@
 static int fname_cmp(const FTSENT * const *, const FTSENT * const *);
 struct store *storecreate(struct store *);
 static int storeappend(struct store *, const char *);
-int getTime(int year, int month, int day);
 
 /*
  * Function to query names of installed packages.
@@ -67,6 +66,12 @@
     FTS *ftsp;
     FTSENT *f;
     Boolean *lmatched = NULL;
+    Boolean dateMatch = FALSE;
+
+    if (MatchType >= 10) {
+	MatchType /= 10;
+	dateMatch = TRUE;
+    }
 
     store = storecreate(store);
     if (store == NULL) {
@@ -113,7 +118,7 @@
 		    matched = f->fts_name;
 		else 
 		    for (i = 0; patterns[i]; i++) {
-			errcode = pattern_match(MatchType, patterns[i], f->fts_name);
+			errcode = pattern_match(MatchType * (dateMatch ? 10 : 1), patterns[i], f->fts_name);
 			if (errcode == 1) {
 			    matched = f->fts_name;
 			    lmatched[i] = TRUE;
@@ -122,8 +127,10 @@
 			if (matched != NULL || errcode != 0)
 			    break;
 		    }
+
 		if (errcode == 0 && matched != NULL)
 		    errcode = storeappend(store, matched);
+		
 		if (errcode != 0) {
 		    if (retval != NULL)
 			*retval = 1;
@@ -253,7 +260,6 @@
 	    break;
 	}
     }
-
     return errcode;
 }
 
@@ -404,45 +410,6 @@
     }
 }
 
-int
-dateMatch(const char *date1, const char *date2)
-{
-    unsigned int year1 = 0, year2 = 0;
-    unsigned int month1 = 0, month2 = 0;
-    unsigned int day1 = 0, day2 = 0;
-    if ((sscanf(date1, "%u %u %u", &year1, &month1, &day1) == 0) ||
- 	(sscanf(date2, "%u %u %u", &year2, &month2, &day2) == 0) ) {
-	
-	warnx("Not valid dates");
-	return -2;
-    }
-
-    if (!(year1 >= 1970 && year1 < 3000) &&
-        !(year2 >= 1970 && year2 < 3000))
-	    warnx("Not valid years");
-
-    if (year1 > year2)
-	return 1;
-    else if (year1 == year2)
-	return 0;
-    else
-	return -1;
-
-    if (month1 > month2)
-	return 1;
-    else if (month1 == month2)
-	return 0;
-    else
-	return -1;
-
-    if (day1 > day2)
-	return 1;
-    else if (day1 == day2)
-	return 0;
-    else
-	return -1;
-}
-
 /*
  * Small linked list to memoize results of isinstalledpkg().  A hash table
  * would be faster but for n ~= 1000 may be overkill.

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

@@ -439,8 +439,12 @@
 	switch (p->type)  {
 	case PLIST_NAME:
 	    name = p->name;
+	    snprintf(tmp, sizeof(tmp), "+D%s", p->name);
 	    if (dbRemove(name) == -1)
 		warnx("%s: Failed to remove entry %s from db", __func__, name);
+
+	    if (dbRemove(tmp) == -1)
+		warnx("%s: Failed to remove installtime entry %s from db", __func__, tmp);
 	    break;
 
 	case PLIST_IGNORE:
@@ -514,7 +518,8 @@
 		    if (dbRemove(tmp) != 0) {
 // 			warnx("%s: Failed to remove entry %s from db", __func__, tmp);
 			if (!CorruptPrinted) {
-			    warnx("The database-cache is probably corrupt; "
+			    warnx("The database-cache is probably corrupt or "
+				  "you don't have the right permissions; "
 				  "Please run pkg_convert after delete to "
 				  "fix it.");
 			    CorruptPrinted = TRUE;



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