Date: Thu, 26 Jun 2008 10:40:25 GMT From: Anders Nore <andenore@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 144138 for review Message-ID: <200806261040.m5QAePTV078507@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=144138 Change 144138 by andenore@andenore_laptop on 2008/06/26 10:40:03 Added support for environment variable PKG_DBCACHE_FILE that can be used to specify the location of the cache file. Affected files ... .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/main.c#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/convert.h#1 add .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/converter.h#1 add .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#2 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/pkg_convert.1#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/main.c#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/perform.c#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/main.c#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#6 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/main.c#4 edit Differences ... ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#4 (text+ko) ==== @@ -24,6 +24,8 @@ - Added global variable 'database' of type DB* (the database object) - Added database helper functions - 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 Create: - The -O option has been modified to cache information when installing ports ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/main.c#3 (text+ko) ==== @@ -111,7 +111,7 @@ if(cacheExists()) { printf("add.main(): cacheExists()\n"); - openDatabase(PKG_DBCACHE_FILE); + openDatabase(); } start = argv; ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#3 (text+ko) ==== @@ -535,7 +535,7 @@ */ /* make sure we've opened the database */ - openDatabase(PKG_DBCACHE_FILE); + openDatabase(); /* save package name (fast lookup in isinstalledpkg) */ printf("Saving package: %s Plist.name\n", Plist.name); ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#2 (text+ko) ==== @@ -1,15 +1,19 @@ #include <stdlib.h> #include <lib.h> -static char Options[] = "v"; -static void usage(); +static char Options[] = "vthepk:"; + +char *Key = NULL; +Boolean CheckExists = FALSE; +Boolean Print = FALSE; +Boolean Textual = TRUE; int main(int argc, char **argv) { char **pkgs; /* null terminated array of installed pkgnames */ int retval, ch; - openDatabase(PKG_DBCACHE_FILE); + openDatabase(); atexit(closeDatabase); signal(SIGHUP, cleanup); @@ -20,6 +24,20 @@ case 'v': Verbose++; break; + case 'e': + CheckExists = TRUE; + break; + case 't': + Textual = FALSE; + break; + case 'p': + Print = TRUE; + break; + case '?': + case 'k': + Key = optarg; + break; + case 'h': default: usage(); break; @@ -36,11 +54,15 @@ } else { printf("No packages to convert\n"); } + + return 0; } -static void +void usage() { - fprintf(stderr, "usage: pkg_convert [-v]\n"); + fprintf(stderr, "usage:\t%s\n\t%s\n", + "pkg_convert [-vtep] [-k key]", + "pkg_convert"); exit(1); } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#4 (text+ko) ==== @@ -5,6 +5,7 @@ #include <err.h> #include "lib.h" +#include "convert.h" static int pkg_do(char *); @@ -13,8 +14,44 @@ { int i, error; error = 0; + DBT data; + + if (CheckExists) { + if (!Key) { + warnx("You must specify a key with -k\n"); + usage(); + exit(1); + } + Boolean exists = dbKeyExists(Key, &data); + if (Textual) { + if (Verbose) + printf("%s exists:\t", Key); + printf("%s\n", exists ? "TRUE" : "FALSE"); + } else { + printf("%s\n", exists ? "1" : "0"); + } + + return 0; + } + + if (Print) { + if (Key != NULL) { + if (dbKeyExists(Key, &data)) + printf("%s -> %s\n", Key, (char *)data.data); + else + printf("%s: does not exist\n", Key); + } else { + DBT key; + while (dbscan(database, &key, &data) == 0) { + printf("%s -> %s\n", (char *)key.data, (char *)data.data); + } + } + + return 0; + } + for (i=0; pkgs[i] != NULL; i++) { - pkg_do(pkgs[i]); + error += pkg_do(pkgs[i]); } return error; @@ -30,17 +67,13 @@ pkg_do(char *pkgname) { char tmp[PATH_MAX]; - DBT key, data; - + 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) */ - FILE *fp; - Package pkg; - PackingList itr; - char *cwd = NULL; - Boolean skip = FALSE; pkg.head = pkg.tail = NULL; pkg.name = pkg.origin = NULL; @@ -56,53 +89,11 @@ fclose(fp); if (pkg.name == NULL || pkg.origin == NULL) { - warnx("%s does not appear to be a valid package!", pkg); + warnx("%s does not appear to be a valid package!", pkg.name); return 1; } return cache_plist(&pkg, Verbose); - - -// key.size = strlen(pkg.name) + 1; -// key.data = pkg.name; -// data.size = strlen(pkg.origin) + 1; -// data.data = pkg.origin; -// -// if(!Quiet) -// printf("Saving package: %s\n", 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 && itr->next) -// printf("\tIgnored: %s\n", 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, itr->name); -// -// key.size = strlen(entry) + 1; -// key.data = entry; -// data.size = strlen(pkgname) + 1; -// data.data = pkgname; -// -// if(Verbose) -// printf("\tSaving entry %s -> %s\n", key.data, data.data); -// dbsave(&key, &data); -// free(entry); -// } -// skip = FALSE; -// } -// free_plist(&pkg); - - return 0; } @@ -119,3 +110,4 @@ } } + ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/pkg_convert.1#3 (text+ko) ==== @@ -34,6 +34,10 @@ .Bl -tag -width indent .It Fl v Turn on verbose output. +.It Fl e Ar key +Checks if key is in database. +.It Fl t +Turns off textual output for key-check (outputs 1 if key exists 0 if not). .El .Sh FILES .Bl -tag -width /var/db/pkg -compact ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#3 (text+ko) ==== @@ -50,10 +50,10 @@ const char *suf; /* Preliminary setup */ - if (InstalledPkg == NULL) - sanity_check(); - if (Verbose && !PlistOnly) - printf("Creating package %s\n", pkg); + if (InstalledPkg == NULL) + sanity_check(); + if (Verbose && !PlistOnly) + printf("Creating package %s\n", pkg); /* chop suffix off if already specified, remembering if we want to compress */ len = strlen(pkg); @@ -240,7 +240,7 @@ * See /usr/ports/Mk/bsd.port.mk (in the fake-pkg target) */ if (PlistOnly) { - openDatabase(PKG_DBCACHE_FILE); + openDatabase(); check_list(home, &plist); int retval = cache_plist(&plist, FALSE); @@ -257,92 +257,100 @@ /* Make first "real contents" pass over it */ check_list(home, &plist); - (void) umask(022); /* - * Make sure gen'ed directories, files don't have - * group or other write bits. - */ - /* copy_plist(home, &plist); */ - /* mark_plist(&plist); */ + (void) umask(022); + /* + * Make sure gen'ed directories, files don't have + * group or other write bits. + */ + + /* copy_plist(home, &plist); */ + /* mark_plist(&plist); */ - /* Now put the release specific items in */ - add_plist(&plist, PLIST_CWD, "."); - write_file(COMMENT_FNAME, Comment); - add_plist(&plist, PLIST_IGNORE, NULL); - add_plist(&plist, PLIST_FILE, COMMENT_FNAME); - add_cksum(&plist, plist.tail, COMMENT_FNAME); - write_file(DESC_FNAME, Desc); - add_plist(&plist, PLIST_IGNORE, NULL); - add_plist(&plist, PLIST_FILE, DESC_FNAME); - add_cksum(&plist, plist.tail, DESC_FNAME); - - if (Install) { - copy_file(home, Install, INSTALL_FNAME); + /* Now put the release specific items in */ + add_plist(&plist, PLIST_CWD, "."); + write_file(COMMENT_FNAME, Comment); add_plist(&plist, PLIST_IGNORE, NULL); - add_plist(&plist, PLIST_FILE, INSTALL_FNAME); - add_cksum(&plist, plist.tail, INSTALL_FNAME); - } - if (PostInstall) { - copy_file(home, PostInstall, POST_INSTALL_FNAME); + add_plist(&plist, PLIST_FILE, COMMENT_FNAME); + add_cksum(&plist, plist.tail, COMMENT_FNAME); + write_file(DESC_FNAME, Desc); add_plist(&plist, PLIST_IGNORE, NULL); - add_plist(&plist, PLIST_FILE, POST_INSTALL_FNAME); - add_cksum(&plist, plist.tail, POST_INSTALL_FNAME); - } - if (DeInstall) { - copy_file(home, DeInstall, DEINSTALL_FNAME); - add_plist(&plist, PLIST_IGNORE, NULL); - add_plist(&plist, PLIST_FILE, DEINSTALL_FNAME); - add_cksum(&plist, plist.tail, DEINSTALL_FNAME); - } - if (PostDeInstall) { - copy_file(home, PostDeInstall, POST_DEINSTALL_FNAME); - add_plist(&plist, PLIST_IGNORE, NULL); - add_plist(&plist, PLIST_FILE, POST_DEINSTALL_FNAME); - add_cksum(&plist, plist.tail, POST_DEINSTALL_FNAME); - } - if (Require) { - copy_file(home, Require, REQUIRE_FNAME); - add_plist(&plist, PLIST_IGNORE, NULL); - add_plist(&plist, PLIST_FILE, REQUIRE_FNAME); - add_cksum(&plist, plist.tail, REQUIRE_FNAME); - } - if (Display) { - copy_file(home, Display, DISPLAY_FNAME); - add_plist(&plist, PLIST_IGNORE, NULL); - add_plist(&plist, PLIST_FILE, DISPLAY_FNAME); - add_cksum(&plist, plist.tail, DISPLAY_FNAME); - add_plist(&plist, PLIST_DISPLAY, DISPLAY_FNAME); - } - if (Mtree) { - copy_file(home, Mtree, MTREE_FNAME); - add_plist(&plist, PLIST_IGNORE, NULL); - add_plist(&plist, PLIST_FILE, MTREE_FNAME); - add_cksum(&plist, plist.tail, MTREE_FNAME); - add_plist(&plist, PLIST_MTREE, MTREE_FNAME); - } + add_plist(&plist, PLIST_FILE, DESC_FNAME); + add_cksum(&plist, plist.tail, DESC_FNAME); + + if (Install) { + copy_file(home, Install, INSTALL_FNAME); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, INSTALL_FNAME); + add_cksum(&plist, plist.tail, INSTALL_FNAME); + } + + if (PostInstall) { + copy_file(home, PostInstall, POST_INSTALL_FNAME); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, POST_INSTALL_FNAME); + add_cksum(&plist, plist.tail, POST_INSTALL_FNAME); + } + + if (DeInstall) { + copy_file(home, DeInstall, DEINSTALL_FNAME); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, DEINSTALL_FNAME); + add_cksum(&plist, plist.tail, DEINSTALL_FNAME); + } + + if (PostDeInstall) { + copy_file(home, PostDeInstall, POST_DEINSTALL_FNAME); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, POST_DEINSTALL_FNAME); + add_cksum(&plist, plist.tail, POST_DEINSTALL_FNAME); + } + + if (Require) { + copy_file(home, Require, REQUIRE_FNAME); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, REQUIRE_FNAME); + add_cksum(&plist, plist.tail, REQUIRE_FNAME); + } + + if (Display) { + copy_file(home, Display, DISPLAY_FNAME); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, DISPLAY_FNAME); + add_cksum(&plist, plist.tail, DISPLAY_FNAME); + add_plist(&plist, PLIST_DISPLAY, DISPLAY_FNAME); + } + + if (Mtree) { + copy_file(home, Mtree, MTREE_FNAME); + add_plist(&plist, PLIST_IGNORE, NULL); + add_plist(&plist, PLIST_FILE, MTREE_FNAME); + add_cksum(&plist, plist.tail, MTREE_FNAME); + add_plist(&plist, PLIST_MTREE, MTREE_FNAME); + } - /* Finally, write out the packing list */ - fp = fopen(CONTENTS_FNAME, "w"); - if (!fp) { - cleanup(0); - errx(2, "%s: can't open file %s for writing", - __func__, CONTENTS_FNAME); - } - write_plist(&plist, fp); - if (fclose(fp)) { - cleanup(0); - errx(2, "%s: error while closing %s", - __func__, CONTENTS_FNAME); - } + /* Finally, write out the packing list */ + fp = fopen(CONTENTS_FNAME, "w"); + if (!fp) { + cleanup(0); + errx(2, "%s: can't open file %s for writing", + __func__, CONTENTS_FNAME); + } + write_plist(&plist, fp); + if (fclose(fp)) { + cleanup(0); + errx(2, "%s: error while closing %s", + __func__, CONTENTS_FNAME); + } - /* And stick it into a tar ball */ - make_dist(home, pkg, suf, &plist); + /* And stick it into a tar ball */ + make_dist(home, pkg, suf, &plist); - /* Cleanup */ - free(Comment); - free(Desc); - free_plist(&plist); - leave_playpen(); - return TRUE; /* Success */ + /* Cleanup */ + free(Comment); + free(Desc); + free_plist(&plist); + leave_playpen(); + return TRUE; /* Success */ } static void ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/main.c#3 (text+ko) ==== @@ -49,7 +49,7 @@ struct stat stat_s; if(cacheExists()) { - openDatabase(PKG_DBCACHE_FILE); + openDatabase(); atexit(closeDatabase); } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/perform.c#3 (text+ko) ==== ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/main.c#5 (text+ko) ==== @@ -55,7 +55,7 @@ /* If cache exists, open it */ if(cacheExists() == TRUE) { - openDatabase(PKG_DBCACHE_FILE); + openDatabase(); atexit(closeDatabase); } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#5 (text+ko) ==== @@ -30,7 +30,7 @@ * TODO: Check if the database is corrupt? Up-to-date? */ Boolean cacheExists() { - if(isfile(PKG_DBCACHE_FILE)) { + if(isfile(DBCACHE_FILE)) { CacheExists = TRUE; return TRUE; } @@ -44,19 +44,27 @@ /* * Opens/creates database file given the filename with read/write permission for user/group */ -DB *opendb(const char *filename) { +DB * +opendb(const char *filename) +{ return dbopen(filename, O_CREAT | O_RDWR, 0666, DB_BTREE, &btinfo); } /* * TODO: Add warnings, verbose check and such + * return 0 on success. */ -void openDatabase(const char *filename) { +int +openDatabase() +{ + printf("Opendatabase: %s\n", DBCACHE_FILE); // DEBUG("openDatabase()\n"); - if(database == NULL) - database = opendb(filename); + if(database == NULL) + database = opendb(DBCACHE_FILE); else DEBUG("openDatabase(): database already open\n"); + + return ( database == NULL ); } /* ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#6 (text+ko) ==== @@ -71,8 +71,13 @@ #define PKG_DBDIR "PKG_DBDIR" /* macro to get name of directory where we put logging information */ #define LOG_DIR (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR) -/* Path to the BDB cache file */ -#define PKG_DBCACHE_FILE "/usr/home/duckjen/projects/soc2008/src/usr.sbin/pkg_install/pkgcache.db" + +/* Default location of the BDB cache file */ +#define DEF_DBCACHE_FILE "/var/db/pkg/pkgcache.db" +/* just in case we change the environment variable name */ +#define PKG_DBCACHE_FILE "PKG_DBCACHE_FILE" +/* macro to get location of cache file where we index information */ +#define DBCACHE_FILE (getenv(PKG_DBCACHE_FILE) ? getenv(PKG_DBCACHE_FILE) : DEF_DBCACHE_FILE) /* The names of our "special" files */ #define CONTENTS_FNAME "+CONTENTS" @@ -248,7 +253,7 @@ /* Database */ Boolean cacheExists(); DB *opendb(const char *filename); -void openDatabase(const char *filename); +int openDatabase(); 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); ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/main.c#4 (text+ko) ==== @@ -43,7 +43,7 @@ int ch, cmp = 0; if(cacheExists()) { - openDatabase(PKG_DBCACHE_FILE); + openDatabase(); atexit(closeDatabase); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806261040.m5QAePTV078507>