Date: Mon, 11 Aug 2008 22:53:12 GMT From: Anders Nore <andenore@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 147189 for review Message-ID: <200808112253.m7BMrCAm094608@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147189 Change 147189 by andenore@andenore_laptop on 2008/08/11 22:53:11 A lot of bug fixing, documenting and man-page writing. Affected files ... .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#11 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/Makefile#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/main.c#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#8 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/converter.h#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#6 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#10 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/pkg_convert.1#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#8 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/perform.c#10 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#6 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/Makefile#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#11 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/date.c#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/deps.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/file.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#14 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/match.c#9 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#9 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/url.c#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/perform.c#5 edit Differences ... ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#11 (text+ko) ==== @@ -16,8 +16,8 @@ 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. + "pkg_info -M '*>2008-07-18 18:30:21'" will list all packages installed after + the date YYYY-MM-DD hh:mm:ss. Add: - Indexes information to dbcache according to the add @@ -28,8 +28,8 @@ 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 + 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: @@ -47,4 +47,4 @@ Packinglist: - - A @comment DATE:seconds-since-epoch has been added (affects add/create/info/lib)+ - A @comment DATE:YYYY-MM-DD hh:mm:ss has been added (affects add/create/info/lib) ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/Makefile#5 (text+ko) ==== @@ -3,7 +3,7 @@ PROG= pkg_add SRCS= main.c perform.c futil.c extract.c -CFLAGS+= -I${.CURDIR}/../lib +CFLAGS+= -I${.CURDIR}/../lib -g WARNS?= 3 WFORMAT?= 1 ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/main.c#5 (text+ko) ==== @@ -95,7 +95,7 @@ static void usage(void); -static char opts[] = "hviIRfFnrp:P:SMt:C:K"; +static char opts[] = "hviIRfFnrp:P:qSMt:C:K"; static struct option longopts[] = { { "chroot", required_argument, NULL, 'C' }, { "dry-run", no_argument, NULL, 'n' }, @@ -181,6 +181,10 @@ errx(1, "-t Argument too long."); break; + case 'q': + Quiet = TRUE; + break; + case 'S': AddMode = SLAVE; break; ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#8 (text+ko) ==== @@ -272,9 +272,8 @@ matched[i]); conflictsfound = 1; } - free(matched[i]); } - free(matched); + continue; } } @@ -300,6 +299,7 @@ printf(" with '%s' origin", deporigin); printf(".\n"); } + if (isinstalledpkg(p->name) <= 0 && !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) { char path[FILENAME_MAX], *cp = NULL; @@ -476,6 +476,9 @@ // warnx("you do not own %s (proceeding anyways)", tmp); // } + if (getuid() != 0) + warnx("not running as root - trying to record install anyway"); + sprintf(LogDir, "%s/%s", LOG_DIR, Plist.name); zapLogDir = 1; if (Verbose) @@ -531,8 +534,8 @@ /* 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); - cache_plist(&Plist, Verbose); // cache information - closeDatabase(); + else + cache_plist(&Plist, Verbose, FALSE); // cache information /* record dependency in the dependents +REQUIRED_BY file */ for (p = Plist.head; p ; p = p->next) { @@ -573,9 +576,11 @@ } } } + if (dep_count > 0) { depmatches = matchallbyorigin((const char **)deporigins, NULL); free(deporigins); + if (!IgnoreDeps && depmatches) { for (i = 0; i < dep_count; i++) { if (depmatches[i]) { ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/converter.h#4 (text+ko) ==== @@ -1,9 +1,31 @@ +/* $FreeBSD$ */ + +/* + * FreeBSD install - a package for the installation and maintainance + * of non-core utilities. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Anders Nore (andenore@FreeBSD.org) + * 12 August 2008 + * + * Various global variables used by pkg_convert + */ + #ifndef _INST_CONVERTER_H #define _INST_CONVERTER_H extern Boolean CheckExists; extern Boolean Textual; extern Boolean Print; +extern Boolean CacheAllDates; extern char * Key; #endif /* _INST_CONVERTER_H */ ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#6 (text+ko) ==== @@ -1,3 +1,25 @@ +/* $FreeBSD$ */ + +/* + * FreeBSD install - a package for the installation and maintainance + * of non-core utilities. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Anders Nore (andenore@FreeBSD.org) + * 12 August 2008 + * + * pkg_convert, a program for caching parts of the flat package-database + * into a berkeley-db file. + */ + #include <stdlib.h> #include <lib.h> #include <getopt.h> @@ -5,10 +27,10 @@ Boolean CheckExists = FALSE; Boolean Print = FALSE; Boolean Textual = FALSE; - +Boolean CacheAllDates = FALSE; void usage(void); -static char opts[] = "vthep"; +static char opts[] = "vdthep"; static struct option longopts[] = { { "verbose", no_argument, NULL, 'v' }, @@ -30,6 +52,9 @@ pkgs = argv; while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { switch(ch) { + case 'd': + CacheAllDates = TRUE; + break; case 'v': Verbose++; break; ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#10 (text+ko) ==== @@ -1,3 +1,23 @@ +/* $FreeBSD$ */ + +/* + * FreeBSD install - a package for the installation and maintainance + * of non-core utilities. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Anders Nore (andenore@FreeBSD.org) + * 12 August 2008 + * + */ + #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> @@ -86,13 +106,9 @@ FILE *fp; Package pkg; - /* - * Add Which indexing i.e. index files installed by package and they point - * to the installed package (alot of redundant data) - */ - pkg.head = pkg.tail = NULL; pkg.name = pkg.origin = NULL; + pkg.datetime = NULL; snprintf(tmp, PATH_MAX, "%s/%s/%s", LOG_DIR, pkgname, CONTENTS_FNAME); fp = fopen(tmp, "r"); @@ -109,7 +125,7 @@ return 1; } - return cache_plist(&pkg, Verbose); + return cache_plist(&pkg, Verbose, CacheAllDates); } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/pkg_convert.1#5 (text+ko) ==== @@ -23,7 +23,7 @@ .Nd a utility for caching information in PKG_DBDIR to a BerkeleyDB file .Sh SYNOPSIS .Nm -.Op Fl v +.Op Fl vd .Op Fl et Ar key .Op Fl p Ar key @@ -37,6 +37,12 @@ .Bl -tag -width indent .It Fl v Turn on verbose output. +.It Fl d +Cache the ctime (time when file status was last changed) of the +COMMENT +file as the installation time for the package for all packages who does +not have a '@comment DATE:YYYY-MM-DD hh:mm:ss' (this should not be a problem +if you always had pkg_tools with installtime support), this is often the +accurate installation time, but not always. .It Fl e Ar key Checks if key is in database. .It Fl p Ar key ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#8 (text+ko) ==== @@ -252,7 +252,7 @@ plist_add_installtime(&plist); check_list(home, &plist); write_plist(&plist, stdout); - int retval = cache_plist(&plist, FALSE); + int retval = cache_plist(&plist, FALSE, FALSE); closeDatabase(); exit(retval); ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/perform.c#10 (text+ko) ==== @@ -340,7 +340,6 @@ /* * Look through package dbs in LOG_DIR and find which * packages installed the files in which_list. - * TODO: Speedup with bdb cache */ static int find_pkg(struct which_head *which_list) @@ -380,18 +379,22 @@ /* If cache exists check database for the key (i.e., file absolute path) */ if (CacheExists == TRUE) { -// DEBUG("find_pkg: USES CACHE\n"); TAILQ_FOREACH(wp, which_list, next) { if (wp->skip == TRUE) continue; DBT tmp; if (dbKeyExists(wp->file, &tmp)) strlcpy(wp->package, tmp.data, PATH_MAX); - else - DEBUG("find_pkg: Doesn't exist\n"); + else { +#ifdef DEBUG + printf("find_pkg: Doesn't exist\n"); +#endif + } } } else { - DEBUG("debug: not using cache; run pkg_convert\n"); +#ifdef DEBUG + printf("debug: not using cache; run pkg_convert\n"); +#endif installed = matchinstalled(MATCH_ALL, NULL, &errcode); if (installed == NULL) return errcode; ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#6 (text+ko) ==== @@ -15,13 +15,7 @@ .\" .\" .\" @(#)pkg_info.1 ->>>> ORIGINAL //depot/vendor/freebsd/src/usr.sbin/pkg_install/info/pkg_info.1#19 -.\" $FreeBSD: src/usr.sbin/pkg_install/info/pkg_info.1,v 1.62 2007/12/09 11:01:58 krion Exp $ -==== THEIRS //depot/vendor/freebsd/src/usr.sbin/pkg_install/info/pkg_info.1#20 .\" $FreeBSD: src/usr.sbin/pkg_install/info/pkg_info.1,v 1.63 2008/05/30 14:26:08 flz Exp $ -==== YOURS //andenore_laptop/src/usr.sbin/pkg_install/info/pkg_info.1 -.\" $FreeBSD: src/usr.sbin/pkg_install/info/pkg_info.1,v 1.60 2007/03/04 13:30:02 ru Exp $ -<<<< .\" .Dd May 30, 2008 .Dt PKG_INFO 1 @@ -31,7 +25,7 @@ .Nd a utility for displaying information on software packages .Sh SYNOPSIS .Nm -.Op Fl bcdDEfghGiIjkKLmnNopPqQrRsvVxX +.Op Fl bcdDEfghGiIjkKLmMnNopPqQrRsvVxX .Op Fl e Ar package .Op Fl l Ar prefix .Op Fl t Ar template @@ -61,7 +55,8 @@ A package name may either be the name of an installed package, the pathname to a package distribution file or a URL to an FTP available package. -Package version numbers can also be matched in a relational manner using the +Package version numbers and installdates (see -M) can also be matched in a +relational manner using the .Pa >= , <= , > and .Pa < @@ -128,6 +123,16 @@ Show the .Xr mtree 8 file (if any) for each package. +.It Fl M +Compare +.Ar pkg-name ... +using installdates instead of version numbers (default). +The format used is 'YYYY-MM-DD hh:mm:ss' +For example, +.Pp +.Dl "pkg_info -M '*>2008-08-11'" +.Pp +will match all packages installed after 2008-08-11. .It Fl L Show the files within each package. This is different from just ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/Makefile#5 (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 date.c -CFLAGS= +CFLAGS=-g WARNS?= 3 WFORMAT?= 1 ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#11 (text+ko) ==== @@ -1,3 +1,24 @@ +/* $FreeBSD$ */ + +/* + * FreeBSD install - a package for the installation and maintainance + * of non-core utilities. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Anders Nore (andenore@FreeBSD.org) + * 12 August 2008 + * + * Various functions for use with berkeley-db (using non-relational btree). + */ + #include "lib.h" #include <assert.h> @@ -63,6 +84,8 @@ database = opendb(DBCACHE_FILE, flags); if (database != NULL) CacheExists = TRUE; + else + warn("Could not open database: %s\n", DBCACHE_FILE); } return ( database == NULL ); @@ -72,13 +95,18 @@ * Put data key/data into database */ int dbput(const DB *db, DBT *key, DBT *data) { - return db->put(db, key, data, 0); + return db->put(db, key, data, 0); } int dbsave(const DBT *key, const DBT *data) { - assert(database != NULL); + assert(database != NULL); + int retval; + + retval = dbput(database, (DBT *)key, (DBT *)data); + if (retval != 0) + warn("%s: cannot save to database", __func__); - return dbput(database, (DBT *)key, (DBT *)data); + return retval; } int dbAddPackage(const char *pkgname, const char *pkgdata) { @@ -148,16 +176,19 @@ * Checks if the given key exists */ Boolean dbKeyExists(const char *aKey, DBT *data) { - assert(database != NULL); + assert(database != NULL); + assert(aKey != NULL); + assert(data != NULL); - DBT key; - key.size = strlen(aKey) + 1; - key.data = (char *)aKey; + DBT key; + key.size = strlen(aKey) + 1; + key.data = (char *)aKey; - if(database->get(database, &key, data, 0) == 0) - return TRUE; - else - return FALSE; + if (database->get(database, &key, data, 0) == 0) { + return TRUE; + } else { + return FALSE; + } } /* @@ -203,38 +234,46 @@ int closedb(DB *db) { - return db->close(db); + int retval = db->close(db); + db = NULL; + return retval; } void closeDatabase() { -// assert(database != NULL); -// DEBUG("closeDatabase()\n"); +// assert(database != NULL); +#ifdef DEBUG + DEBUG("closeDatabase()\n"); +#endif if(database != NULL) closedb(database); +#ifdef DEBUG else DEBUG("closeDatbase(): Database already closed()\n"); +#endif } /* * cache_plist - * Caches the information about the package pkg into the database + * Caches the information about the package pkg into the database: + * pkgname -> origin (for origin lookup) + * +Dpkgname -> installdatetime (for datetime lookup range search) + * installed-file -> pkgname (for "which" searching pkg_info -w) */ int -cache_plist(Package *pkg, Boolean showmsg) +cache_plist(Package *pkg, Boolean showmsg, Boolean cacheAllDates) { PackingList itr = NULL; Boolean skip = FALSE; char *cwd; DBT key, data; - time_t etime; + char *szTime; struct stat fstat; if (pkg->name == NULL || pkg->origin == NULL) { - if (showmsg) - warnx("%s does not appear to be a valid package!", pkg->name); + warnx("%s does not appear to be a valid package!", pkg->name); return 1; } @@ -278,28 +317,31 @@ } /* Cache installtime */ - if (pkg->datetime != 0) - etime = pkg->datetime; - else { + if (pkg->datetime != NULL) { + szTime = pkg->datetime; + } else if (cacheAllDates) { char path[PATH_MAX]; 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_ctime; + szTime = getDateString(fstat.st_ctime); } - char *tmp[128], tmp2[128]; + char tmp[128], tmp2[128]; snprintf(&tmp, sizeof(tmp), "+D%s", pkg->name); - snprintf(&tmp2, sizeof(tmp2), "%d", (int)etime); + snprintf(&tmp2, sizeof(tmp2), "%s", szTime); key.size = strlen(tmp) + 1; key.data = (char *)tmp; data.size = strlen(tmp2) + 1; data.data = (char *)tmp2; - dbsave(&key, &data); - if (Verbose && showmsg) - printf("Saving installdate: %s %s\n", tmp, tmp2); + /* Only cache installtime if we have one or we want one */ + if (pkg->datetime || cacheAllDates) { + if (Verbose && showmsg) + printf("Saving installdate: %s -> %s\n", tmp, tmp2); + dbsave(&key, &data); + } return 0; } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/date.c#3 (text+ko) ==== @@ -1,45 +1,90 @@ +/* $FreeBSD$ */ +/* + * FreeBSD install - a package for the installation and maintainance + * of non-core utilities. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Anders Nore (andenore@FreeBSD.org) + * 12 August 2008 + * + * Various functions for date and time handling. + */ + #include "lib.h" +/* + * getInstallDate - gets the installdate for pkgname if it exists + * If successful returns second-since-epoch of the installdate otherwise + * return -1. + */ int getInstallDate(const char *pkgname) { - int result = 0; + unsigned int year = 0; + unsigned int month = 0; + unsigned int day = 0; + unsigned int hour = 0; + unsigned int minute = 0; + unsigned int second = 0; char path[PATH_MAX]; FILE *fp; Package plist; + DBT data; + bzero(&data, sizeof(data)); bzero(&plist, sizeof(plist)); if (CacheExists) { char key[1024]; - DBT data; snprintf(key, sizeof(key), "+D%s", pkgname); - if (dbKeyExists(key, &data)) { - if(sscanf(data.data, "%d", &result) == 0) { - warnx("getInstallDate: Database may be corrupt"); - return -1; - } else { - return result; - } + if (!dbKeyExists(key, &data)) { + warnx("Could not get installdate for package '%s', if you want to cache " + "information for all packages see pkg_convert(1).\n", pkgname); + return -1; + } + } else { + + /* If we don't have cache (reading plist = SLOW) */ + snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, pkgname, CONTENTS_FNAME); + + fp = fopen(path, "r"); + if (!fp) { + warn("Could not open %s", path); + return -1; } + read_plist(&plist, fp); + data.data = plist.datetime; } - /* 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); + if (data.data == NULL) + return -1; - fp = fopen(path, "r"); - if (!fp) { - warn("Could not open %s", path); - return 0; + if (sscanf(data.data, "%u-%u-%u %u:%u:%u", &year, &month, &day, &hour, &minute, &second) != 0) { + return getTime(year, month, day, hour, minute, second); + } else { + warnx("%u-%u-%u %u:%u", year, month, day, hour, minute, second); + warnx("Invalid datetime format: %s", data.data); + return -1; } - read_plist(&plist, fp); - - return plist.datetime; } +/* + * getTime - gets the time in seconds-since-epoch of the variables + * supplied. + * returns -1 on failure. + */ int -getTime(int year, int month, int day) +getTime(unsigned int year, unsigned int month, unsigned int day, + unsigned int hour, unsigned int minute, unsigned int second) { time_t rawtime; struct tm *timeinfo; @@ -49,22 +94,43 @@ timeinfo->tm_year = year - 1900; timeinfo->tm_mon = month - 1; timeinfo->tm_mday = day; + timeinfo->tm_hour = hour; + timeinfo->tm_min = minute; + timeinfo->tm_sec = second; - return mktime(timeinfo); + /* + * Get the time, if the date > 2038-01-18 we get the wrong time and + * result = -1, this is because of the y2k+38 bug. + */ + int result = mktime(timeinfo); + if (result == -1) + warnx("could not get correct time, output may be incorrect, check your input.\n"); + return result; } +/* + * date_cmp - compares the installtime of pkgname to the date string *date + * with format "YYYY-MM-DD hh:mm:ss". + * returns: + * 1 if pkgname > date + * 0 if pkgname == date + * -1 if pkgname < date + */ int date_cmp(const char *pkgname, const char *date) { unsigned int year = 0; unsigned int month = 0; unsigned int day = 0; + unsigned int hour = 0; + unsigned int minute = 0; + unsigned int second = 0; - if ((sscanf(date, "%u %u %u", &year, &month, &day) == 0)) - warnx("Invalid date format: %s", date); + if ((sscanf(date, "%u-%u-%u %u:%u:%u", &year, &month, &day, &hour, &minute, &second) == 0)) + warnx("Invalid datetime format: %s", date); int time1 = getInstallDate(pkgname); - int time2 = getTime(year, month, day); + int time2 = getTime(year, month, day, hour, minute, second); if (time1 > time2) { return 1; @@ -73,4 +139,23 @@ } else { return -1; } +} + +/* + * getDateString - returns a string of format "YYYY-MM-DD hh:mm:ss" + * representing the seconds-since-epoch clock variable. + * NB: The string returned is static, so calling this function more than once + * will alter a previously return string. + */ +char * +getDateString(const time_t clock) +{ + struct tm *installTime; + static char timeString[80]; + + installTime = localtime(&clock); + snprintf(&timeString, sizeof(timeString), "%u-%02u-%02u %02u:%02u:%02u", + installTime->tm_year + 1900, installTime->tm_mon + 1, installTime->tm_mday, + installTime->tm_hour, installTime->tm_min, installTime->tm_sec); + return timeString; } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/deps.c#4 (text+ko) ==== @@ -254,12 +254,13 @@ void fix_dependencies(char *pkgname) { - int i; + int i, errcode; char **matched; PackingList p = NULL; + if (Verbose) printf("Recording existing dependency's on %s\n", pkgname); - int errcode; + matched = matchinstalled(MATCH_ALL, NULL, &errcode); for (i = 0; matched[i] != NULL; i++) { FILE *fp; @@ -296,7 +297,5 @@ } } free_plist(&nplist); - free(matched[i]); } - free(matched); } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/file.c#4 (text+ko) ==== @@ -29,6 +29,10 @@ char sizeTable[][5] = { "Byte", "kB", "MB", "GB", "TB" }; +int power(int , int); +char *printHumanReadable(unsigned int); +unsigned int human_readable(unsigned int, int *, unsigned int, int *); + /* Quick check to see if a file exists */ Boolean fexists(const char *fname) @@ -473,7 +477,7 @@ printHumanReadable(unsigned int size) { static char result[32]; - int index = 0; + unsigned int index = 0; int tmpSize = 0, precision = 0; tmpSize = human_readable(size, &precision, 1, &index); ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#14 (text+ko) ==== @@ -122,8 +122,6 @@ #define PLIST_FMT_VER_MAJOR 1 #define PLIST_FMT_VER_MINOR 1 -#define DEBUG(s) printf(s) - enum _plist_t { PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD, PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE, @@ -154,7 +152,8 @@ struct _plist *head, *tail; const char *name; const char *origin; - int fmtver_maj, fmtver_mnr, datetime; + const char *datetime; + int fmtver_maj, fmtver_mnr; }; typedef struct _pack Package; @@ -265,12 +264,14 @@ Boolean dbPackageExists(const char *portname); void closeDatabase(void); int dbScan(DBT *key, DBT *data); -int cache_plist(Package *pkg, Boolean showmsg); +int cache_plist(Package *pkg, Boolean showmsg, Boolean cacheAllDates); /* Date */ int getInstallDate(const char *pkgname); -int getTime(int year, int month, int day); +int getTime(unsigned int year, unsigned int month, unsigned int day, + unsigned int hour, unsigned int minute, unsigned int second); int date_cmp(const char *pkgname, const char *date); +char *getDateString(const time_t clock); /* Externs */ extern Boolean Quiet; ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/match.c#9 (text+ko) ==== @@ -47,6 +47,8 @@ /* * Function to query names of installed packages. * MatchType - one of MATCH_ALL, MATCH_EREGEX, MATCH_REGEX, MATCH_GLOB, MATCH_NGLOB; + if MatchType = (MatchType * 10) then the comparison with <>=! is done + with the installation date instead of version comparison. * patterns - NULL-terminated list of glob or regex patterns * (could be NULL for MATCH_ALL); * retval - return value (could be NULL if you don't want/need @@ -94,9 +96,9 @@ /* Count number of patterns */ if (patterns != NULL) { for (len = 0; patterns[len]; len++) {} - lmatched = alloca(sizeof(*lmatched) * len); + lmatched = malloc(sizeof(*lmatched) * len); if (lmatched == NULL) { - warnx("%s(): alloca() failed", __func__); + warnx("%s(): malloc() failed", __func__); if (retval != NULL) *retval = 1; return NULL; @@ -116,7 +118,7 @@ errcode = 0; if (MatchType == MATCH_ALL) matched = f->fts_name; - else + else for (i = 0; patterns[i]; i++) { errcode = pattern_match(MatchType * (dateMatch ? 10 : 1), patterns[i], f->fts_name); if (errcode == 1) { @@ -127,10 +129,10 @@ if (matched != NULL || errcode != 0) break; } - + if (errcode == 0 && matched != NULL) errcode = storeappend(store, matched); - + if (errcode != 0) { if (retval != NULL) *retval = 1; @@ -147,6 +149,7 @@ if (lmatched[i] == FALSE) storeappend(store, patterns[i]); } + free(lmatched); if (store->used == 0) return NULL; @@ -275,7 +278,6 @@ int i, j; Boolean CorruptPrinted = FALSE; - if (retval != NULL) *retval = 0; @@ -298,8 +300,8 @@ */ if (CacheExists) { DBT data; - - if(dbKeyExists(installed[i], &data)) { + + if (dbKeyExists(installed[i], &data)) { asprintf(&buf, "%s", (char *)data.data); allorigins[i] = buf; continue; @@ -326,6 +328,7 @@ snprintf(tmp, PATH_MAX, "%s/%s", tmp, CONTENTS_FNAME); fp = fopen(tmp, "r"); if (fp == NULL) { + printf("tmp = %s\n", tmp); warnx("the package info for package '%s' is corrupt", installed[i]); continue; } @@ -370,12 +373,12 @@ storeappend(store, installed[j]); } } + } - if (store->used == 0) - matches[i] = NULL; - else - matches[i] = store->store; - } + if (store->used == 0) + matches[i] = NULL; + else + matches[i] = store->store; } if (allorigins) { @@ -629,10 +632,10 @@ store->currlen = 0; store->store = NULL; } else if (store->store != NULL) { - /* Free previously allocated memory */ - for (i = 0; store->store[i] != NULL; i++) - free(store->store[i]); - store->store[0] = NULL; + /* Free previously allocated memory */ + for (i = 0; store->store[i] != NULL; i++) + free(store->store[i]); + store->store[0] = NULL; } store->used = 0; @@ -645,31 +648,31 @@ static int storeappend(struct store *store, const char *item) { - if (store->used + 2 > store->currlen) { >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808112253.m7BMrCAm094608>