Date: Wed, 2 Jul 2008 17:41:56 GMT From: Anders Nore <andenore@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 144499 for review Message-ID: <200807021741.m62HfuWN074750@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=144499 Change 144499 by andenore@andenore_laptop on 2008/07/02 17:41:54 A lot of small fixes and merging. I think everything works with what I've done so far. Affected files ... .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile#3 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile.inc#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/main.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/pkg_add.1#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/create.h#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/main.c#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/pkg_create.1#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/main.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/perform.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/pkg_delete.1#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/Makefile#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/info.h#2 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/main.c#6 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/perform.c#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/pkg_info.1#3 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#6 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/file.c#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#7 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/match.c#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/url.c#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/updating/main.c#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/updating/pkg_updating.1#2 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/main.c#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/pkg_version.1#2 integrate Differences ... ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#5 (text+ko) ==== @@ -4,6 +4,7 @@ Converter: - Added convert program that indexes information to PKG_DBCACHE_FILE + - Added some features to lookup keys and print them (or print whole db) Info: - Improved performance for -W option using the dbcache @@ -20,7 +21,7 @@ - Deindexes information according to the delete Lib: - - Changed methods in match.c to use cache if available + - Changed methods in match.c to use cache if available (matchallbyorigin, ispkginstalled) - Added global variable 'database' of type DB* (the database object) - Added database helper functions - Added function to cache a Packagelist (cache_plist()) ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile#3 (text+ko) ==== @@ -1,4 +1,4 @@ -# $FreeBSD: src/usr.sbin/pkg_install/Makefile,v 1.22 2008/04/09 15:08:31 flz Exp $ +# $FreeBSD: src/usr.sbin/pkg_install/Makefile,v 1.25 2008/06/16 09:15:27 flz Exp $ .include <bsd.own.mk> @@ -6,18 +6,15 @@ .include <bsd.subdir.mk> -CP= /bin/cp -RM= /bin/rm -TAR= /usr/bin/tar - -DATE!= date +%Y%m%d +DATE!= grep PKG_INSTALL_VERSION ${.CURDIR}/lib/lib.h | sed 's|.*[ ]||' distfile: clean @(cd ${.CURDIR}/..; \ - ${CP} -r pkg_install pkg_install-${DATE}; \ - ${TAR} -czf pkg_install/pkg_install-${DATE}.tar.gz \ + cp -r pkg_install pkg_install-${DATE}; \ + tar -czf pkg_install/pkg_install-${DATE}.tar.gz \ --exclude .#* --exclude *~ --exclude CVS \ - --exclude pkg_install-*.tar.gz pkg_install-${DATE}; \ - ${RM} -rf pkg_install-${DATE}) + --exclude .svn --exclude pkg_install-*.tar.gz \ + pkg_install-${DATE}; \ + rm -rf pkg_install-${DATE}) ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile.inc#2 (text+ko) ==== @@ -1,4 +1,4 @@ -# $FreeBSD: src/usr.sbin/pkg_install/Makefile.inc,v 1.14 2006/03/17 18:54:42 ru Exp $ +# $FreeBSD: src/usr.sbin/pkg_install/Makefile.inc,v 1.16 2008/05/03 23:17:37 pav Exp $ .include <bsd.own.mk> @@ -11,4 +11,4 @@ .endif # Inherit BINDIR from one level up. -.include "../Makefile.inc" +#.include "../Makefile.inc" ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/main.c#4 (text+ko) ==== @@ -19,16 +19,16 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/add/main.c,v 1.76 2008/02/26 14:35:01 kensmith Exp $"); +__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/add/main.c,v 1.78 2008/06/16 23:41:11 flz Exp $"); -#include <err.h> #include <sys/param.h> #include <sys/utsname.h> +#include <err.h> +#include <getopt.h> + #include "lib.h" #include "add.h" -static char Options[] = "hviIRfFnrp:P:SMt:C:K"; - char *Prefix = NULL; Boolean PrefixRecursive = FALSE; char *Chroot = NULL; @@ -95,246 +95,257 @@ static void usage(void); +static char opts[] = "hviIRfFnrp:P:SMt:C:K"; +static struct option longopts[] = { + { "chroot", required_argument, NULL, 'C' }, + { "dry-run", no_argument, NULL, 'n' }, + { "force", no_argument, NULL, 'f' }, + { "help", no_argument, NULL, 'h' }, + { "keep", no_argument, NULL, 'K' }, + { "master", no_argument, NULL, 'M' }, + { "no-deps", no_argument, NULL, 'i' }, + { "no-record", no_argument, NULL, 'R' }, + { "no-script", no_argument, NULL, 'I' }, + { "prefix", required_argument, NULL, 'p' }, + { "remote", no_argument, NULL, 'r' }, + { "template", required_argument, NULL, 't' }, + { "slave", no_argument, NULL, 'S' }, + { "verbose", no_argument, NULL, 'v' }, + { NULL, 0, NULL, 0 } +}; + int main(int argc, char **argv) { - int ch, error; - char **start; - char *cp, *packagesite = NULL, *remotepkg = NULL, *ptr; - static char temppackageroot[MAXPATHLEN]; - static char pkgaddpath[MAXPATHLEN]; + int ch, error; + char **start; + char *cp, *packagesite = NULL, *remotepkg = NULL, *ptr; + static char temppackageroot[MAXPATHLEN]; + static char pkgaddpath[MAXPATHLEN]; + + if (*argv[0] != '/' && strchr(argv[0], '/') != NULL) + PkgAddCmd = realpath(argv[0], pkgaddpath); + else + PkgAddCmd = argv[0]; + + openDatabase(O_CREAT | O_RDWR); + atexit(closeDatabase); + + start = argv; + while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { + switch(ch) { + case 'v': + Verbose++; + break; + + case 'p': + Prefix = optarg; + PrefixRecursive = FALSE; + break; + + case 'P': + Prefix = optarg; + PrefixRecursive = TRUE; + break; + + case 'I': + NoInstall = TRUE; + break; + + case 'R': + NoRecord = TRUE; + break; + + case 'f': + Force = TRUE; + break; + + case 'F': + FailOnAlreadyInstalled = FALSE; + break; + + case 'K': + KeepPackage = TRUE; + break; + + case 'n': + Fake = TRUE; + break; + + case 'r': + Remote = TRUE; + break; + + case 't': + if (strlcpy(FirstPen, optarg, sizeof(FirstPen)) >= sizeof(FirstPen)) + errx(1, "-t Argument too long."); + break; + + case 'S': + AddMode = SLAVE; + break; + + case 'M': + AddMode = MASTER; + break; - if (*argv[0] != '/' && strchr(argv[0], '/') != NULL) - PkgAddCmd = realpath(argv[0], pkgaddpath); - else - PkgAddCmd = argv[0]; + case 'C': + Chroot = optarg; + break; - if(cacheExists()) { - printf("add.main(): cacheExists()\n"); - openDatabase(); - } + case 'i': + IgnoreDeps = TRUE; + break; - start = argv; - while ((ch = getopt(argc, argv, Options)) != -1) { - switch(ch) { - case 'v': - Verbose++; - break; - - case 'p': - Prefix = optarg; - PrefixRecursive = FALSE; - break; - - case 'P': - Prefix = optarg; - PrefixRecursive = TRUE; - break; - - case 'I': - NoInstall = TRUE; - break; - - case 'R': - NoRecord = TRUE; - break; - - case 'f': - Force = TRUE; - break; - - case 'F': - FailOnAlreadyInstalled = FALSE; - break; - - case 'K': - KeepPackage = TRUE; - break; - - case 'n': - Fake = TRUE; - break; - - case 'r': - Remote = TRUE; - break; - - case 't': - if (strlcpy(FirstPen, optarg, sizeof(FirstPen)) >= sizeof(FirstPen)) - errx(1, "-t Argument too long."); - break; - - case 'S': - AddMode = SLAVE; - break; - - case 'M': - AddMode = MASTER; - break; - - case 'C': - Chroot = optarg; - break; - case 'i': - IgnoreDeps = TRUE; - break; - - case 'h': - case '?': - default: - usage(); - break; - } + case 'h': + default: + usage(); + break; } - argc -= optind; - argv += optind; + } + argc -= optind; + argv += optind; - if (AddMode != SLAVE) { - pkgs = (char **)malloc((argc+1) * sizeof(char *)); - for (ch = 0; ch <= argc; pkgs[ch++] = NULL) ; + if (AddMode != SLAVE) { + pkgs = (char **)malloc((argc+1) * sizeof(char *)); + for (ch = 0; ch <= argc; pkgs[ch++] = NULL) ; - /* Get all the remaining package names, if any */ - for (ch = 0; *argv; ch++, argv++) { - char temp[MAXPATHLEN]; - if (Remote) { - if ((packagesite = getpackagesite()) == NULL) - errx(1, "package name too long"); - if (strlcpy(temppackageroot, packagesite, - sizeof(temppackageroot)) >= sizeof(temppackageroot)) - errx(1, "package name too long"); - if (strlcat(temppackageroot, *argv, sizeof(temppackageroot)) - >= sizeof(temppackageroot)) - errx(1, "package name too long"); - remotepkg = temppackageroot; - if (!((ptr = strrchr(remotepkg, '.')) && ptr[1] == 't' && - (ptr[2] == 'b' || ptr[2] == 'g') && ptr[3] == 'z' && - !ptr[4])) - if (strlcat(remotepkg, -#if defined(__FreeBSD_version) && __FreeBSD_version >= 500039 - ".tbz", -#else - ".tgz", -#endif - sizeof(temppackageroot)) >= sizeof(temppackageroot)) - errx(1, "package name too long"); + /* Get all the remaining package names, if any */ + for (ch = 0; *argv; ch++, argv++) { + char temp[MAXPATHLEN]; + if (Remote) { + if ((packagesite = getpackagesite()) == NULL) + errx(1, "package name too long"); + if (strlcpy(temppackageroot, packagesite, + sizeof(temppackageroot)) >= sizeof(temppackageroot)) + errx(1, "package name too long"); + if (strlcat(temppackageroot, *argv, sizeof(temppackageroot)) + >= sizeof(temppackageroot)) + errx(1, "package name too long"); + remotepkg = temppackageroot; + if (!((ptr = strrchr(remotepkg, '.')) && ptr[1] == 't' && + (ptr[2] == 'b' || ptr[2] == 'g') && ptr[3] == 'z' && + !ptr[4])) + if (strlcat(remotepkg, ".tbz", + sizeof(temppackageroot)) >= sizeof(temppackageroot)) + errx(1, "package name too long"); } - if (!strcmp(*argv, "-")) /* stdin? */ - pkgs[ch] = (char *)"-"; - else if (isURL(*argv)) { /* preserve URLs */ - if (strlcpy(temp, *argv, sizeof(temp)) >= sizeof(temp)) - errx(1, "package name too long"); - pkgs[ch] = strdup(temp); - } - else if ((Remote) && isURL(remotepkg)) { - if (strlcpy(temp, remotepkg, sizeof(temp)) >= sizeof(temp)) - errx(1, "package name too long"); - pkgs[ch] = strdup(temp); - } else { /* expand all pathnames to fullnames */ - if (fexists(*argv)) /* refers to a file directly */ - pkgs[ch] = strdup(realpath(*argv, temp)); - else { /* look for the file in the expected places */ - if (!(cp = fileFindByPath(NULL, *argv))) { - /* let pkg_do() fail later, so that error is reported */ - if (strlcpy(temp, *argv, sizeof(temp)) >= sizeof(temp)) - errx(1, "package name too long"); - pkgs[ch] = strdup(temp); - } else { - if (strlcpy(temp, cp, sizeof(temp)) >= sizeof(temp)) - errx(1, "package name too long"); - pkgs[ch] = strdup(temp); - } - } - } - if (packagesite != NULL) - packagesite[0] = '\0'; + if (!strcmp(*argv, "-")) /* stdin? */ + pkgs[ch] = (char *)"-"; + else if (isURL(*argv)) { /* preserve URLs */ + if (strlcpy(temp, *argv, sizeof(temp)) >= sizeof(temp)) + errx(1, "package name too long"); + pkgs[ch] = strdup(temp); + } + else if ((Remote) && isURL(remotepkg)) { + if (strlcpy(temp, remotepkg, sizeof(temp)) >= sizeof(temp)) + errx(1, "package name too long"); + pkgs[ch] = strdup(temp); + } else { /* expand all pathnames to fullnames */ + if (fexists(*argv)) /* refers to a file directly */ + pkgs[ch] = strdup(realpath(*argv, temp)); + else { /* look for the file in the expected places */ + if (!(cp = fileFindByPath(NULL, *argv))) { + /* let pkg_do() fail later, so that error is reported */ + if (strlcpy(temp, *argv, sizeof(temp)) >= sizeof(temp)) + errx(1, "package name too long"); + pkgs[ch] = strdup(temp); + } else { + if (strlcpy(temp, cp, sizeof(temp)) >= sizeof(temp)) + errx(1, "package name too long"); + pkgs[ch] = strdup(temp); + } } + } + if (packagesite != NULL) + packagesite[0] = '\0'; } - - /* If no packages, yelp */ - else if (!ch) { - warnx("missing package name(s)"); - usage(); - } - else if (ch > 1 && AddMode == MASTER) { - warnx("only one package name may be specified with master mode"); - usage(); - } - - /* Perform chroot if requested */ - if (Chroot != NULL) { - if (chroot(Chroot)) - errx(1, "chroot to %s failed", Chroot); - } - /* Make sure the sub-execs we invoke get found */ - setenv("PATH", - "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin", - 1); + } + /* If no packages, yelp */ + else if (!ch) { + warnx("missing package name(s)"); + usage(); + } + else if (ch > 1 && AddMode == MASTER) { + warnx("only one package name may be specified with master mode"); + usage(); + } + /* Perform chroot if requested */ + if (Chroot != NULL) { + if (chroot(Chroot)) + errx(1, "chroot to %s failed", Chroot); + } + /* Make sure the sub-execs we invoke get found */ + setenv("PATH", + "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin", + 1); - /* Set a reasonable umask */ - umask(022); + /* Set a reasonable umask */ + umask(022); - if ((error = pkg_perform(pkgs)) != 0) { - if (Verbose) - warnx("%d package addition(s) failed", error); - return error; - } - else - return 0; + if ((error = pkg_perform(pkgs)) != 0) { + if (Verbose) + warnx("%d package addition(s) failed", error); + return error; + } + else + return 0; } static char * getpackagesite(void) { - int reldate, i; - static char sitepath[MAXPATHLEN]; - struct utsname u; + int reldate, i; + static char sitepath[MAXPATHLEN]; + struct utsname u; + + if (getenv("PACKAGESITE")) { + if (strlcpy(sitepath, getenv("PACKAGESITE"), sizeof(sitepath)) + >= sizeof(sitepath)) + return NULL; + return sitepath; + } + + if (getenv("PACKAGEROOT")) { + if (strlcpy(sitepath, getenv("PACKAGEROOT"), sizeof(sitepath)) + >= sizeof(sitepath)) + return NULL; + } else { + if (strlcat(sitepath, "ftp://ftp.freebsd.org", sizeof(sitepath)) + >= sizeof(sitepath)) + return NULL; + } - if (getenv("PACKAGESITE")) { - if (strlcpy(sitepath, getenv("PACKAGESITE"), sizeof(sitepath)) - >= sizeof(sitepath)) - return NULL; - return sitepath; - } + if (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath)) + >= sizeof(sitepath)) + return NULL; - if (getenv("PACKAGEROOT")) { - if (strlcpy(sitepath, getenv("PACKAGEROOT"), sizeof(sitepath)) - >= sizeof(sitepath)) - return NULL; - } else { - if (strlcat(sitepath, "ftp://ftp.freebsd.org", sizeof(sitepath)) - >= sizeof(sitepath)) - return NULL; - } + uname(&u); + if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath)) + return NULL; - if (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath)) + reldate = getosreldate(); + for(i = 0; releases[i].directory != NULL; i++) { + if (reldate >= releases[i].lowver && reldate <= releases[i].hiver) { + if (strlcat(sitepath, releases[i].directory, sizeof(sitepath)) >= sizeof(sitepath)) - return NULL; - - uname(&u); - if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath)) return NULL; + break; + } + } - reldate = getosreldate(); - for(i = 0; releases[i].directory != NULL; i++) { - if (reldate >= releases[i].lowver && reldate <= releases[i].hiver) { - if (strlcat(sitepath, releases[i].directory, sizeof(sitepath)) - >= sizeof(sitepath)) - return NULL; - break; - } - } + if (strlcat(sitepath, "/Latest/", sizeof(sitepath)) >= sizeof(sitepath)) + return NULL; - if (strlcat(sitepath, "/Latest/", sizeof(sitepath)) >= sizeof(sitepath)) - return NULL; + return sitepath; - return sitepath; } static void usage() { - fprintf(stderr, "%s\n%s\n", + fprintf(stderr, "%s\n%s\n", "usage: pkg_add [-viInfFrRMSK] [-t template] [-p prefix] [-P prefix] [-C chrootdir]", " pkg-name [pkg-name ...]"); - exit(1); + exit(1); } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#4 (text+ko) ==== @@ -19,7 +19,7 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/add/perform.c,v 1.83 2008/04/11 08:26:06 pav Exp $"); +__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/add/perform.c,v 1.86 2008/06/16 23:41:11 flz Exp $"); #include <err.h> #include <paths.h> @@ -29,6 +29,7 @@ #include <libgen.h> #include <signal.h> #include <sys/wait.h> +#include <sys/stat.h> static int pkg_do(char *); static int sanity_check(char *); @@ -38,18 +39,18 @@ int pkg_perform(char **pkgs) { - int i, err_cnt = 0; + int i, err_cnt = 0; - signal(SIGINT, cleanup); - signal(SIGHUP, cleanup); + signal(SIGINT, cleanup); + signal(SIGHUP, cleanup); - if (AddMode == SLAVE) - err_cnt = pkg_do(NULL); - else { - for (i = 0; pkgs[i]; i++) - err_cnt += pkg_do(pkgs[i]); - } - return err_cnt; + if (AddMode == SLAVE) + err_cnt = pkg_do(NULL); + else { + for (i = 0; pkgs[i]; i++) + err_cnt += pkg_do(pkgs[i]); + } + return err_cnt; } static Package Plist; @@ -63,678 +64,643 @@ static int pkg_do(char *pkg) { - char pkg_fullname[FILENAME_MAX]; - char playpen[FILENAME_MAX]; - char extract_contents[FILENAME_MAX]; - char *where_to, *extract; - FILE *cfile; - int code; - PackingList p; - struct stat sb; - int inPlace, conflictsfound, errcode; - /* support for separate pre/post install scripts */ - int new_m = 0; - char pre_script[FILENAME_MAX] = INSTALL_FNAME; - char post_script[FILENAME_MAX]; - char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX]; - char *conflict[2]; - char **matched; + char pkg_fullname[FILENAME_MAX]; + char playpen[FILENAME_MAX]; + char extract_contents[FILENAME_MAX]; + char *where_to, *extract; + FILE *cfile; + int code; + PackingList p; + struct stat sb; + int inPlace, conflictsfound, errcode; + /* support for separate pre/post install scripts */ + int new_m = 0; + char pre_script[FILENAME_MAX] = INSTALL_FNAME; + char post_script[FILENAME_MAX]; + char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX]; + char *conflict[2]; + char **matched; - conflictsfound = 0; - code = 0; - zapLogDir = 0; - LogDir[0] = '\0'; - strcpy(playpen, FirstPen); - inPlace = 0; + conflictsfound = 0; + code = 0; + zapLogDir = 0; + LogDir[0] = '\0'; + strcpy(playpen, FirstPen); + inPlace = 0; - /* Are we coming in for a second pass, everything already extracted? */ - if (!pkg) { - fgets(playpen, FILENAME_MAX, stdin); - playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */ - if (chdir(playpen) == FAIL) { - warnx("pkg_add in SLAVE mode can't chdir to %s", playpen); - return 1; - } - read_plist(&Plist, stdin); - where_to = playpen; + /* Are we coming in for a second pass, everything already extracted? */ + if (!pkg) { + fgets(playpen, FILENAME_MAX, stdin); + playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */ + if (chdir(playpen) == FAIL) { + warnx("pkg_add in SLAVE mode can't chdir to %s", playpen); + return 1; + } + read_plist(&Plist, stdin); + where_to = playpen; + } + /* Nope - do it now */ + else { + /* Is it an ftp://foo.bar.baz/file.t[bg]z specification? */ + if (isURL(pkg)) { + if (!(Home = fileGetURL(NULL, pkg, KeepPackage))) { + warnx("unable to fetch '%s' by URL", pkg); + return 1; + } + where_to = Home; + strcpy(pkg_fullname, pkg); + cfile = fopen(CONTENTS_FNAME, "r"); + if (!cfile) { + warnx( + "unable to open table of contents file '%s' - not a package?", + CONTENTS_FNAME); + goto bomb; + } + read_plist(&Plist, cfile); + fclose(cfile); } - /* Nope - do it now */ else { - /* Is it an ftp://foo.bar.baz/file.t[bg]z specification? */ - if (isURL(pkg)) { - if (!(Home = fileGetURL(NULL, pkg, KeepPackage))) { - warnx("unable to fetch '%s' by URL", pkg); - return 1; - } - where_to = Home; - strcpy(pkg_fullname, pkg); - cfile = fopen(CONTENTS_FNAME, "r"); - if (!cfile) { - warnx( - "unable to open table of contents file '%s' - not a package?", - CONTENTS_FNAME); - - goto bomb; - } - read_plist(&Plist, cfile); - fclose(cfile); + strcpy(pkg_fullname, pkg); /* + * Copy for sanity's sake, + * could remove pkg_fullname + */ + if (strcmp(pkg, "-")) { + if (stat(pkg_fullname, &sb) == FAIL) { + warnx("can't stat package file '%s'", pkg_fullname); + goto bomb; } - else { - strcpy(pkg_fullname, pkg); /* - * Copy for sanity's sake, - * could remove pkg_fullname - */ - if (strcmp(pkg, "-")) { - if (stat(pkg_fullname, &sb) == FAIL) { - warnx("can't stat package file '%s'", pkg_fullname); - goto bomb; - } - sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME); - extract = extract_contents; - } - else { - extract = NULL; - sb.st_size = 100000; /* Make up a plausible average size */ - } - - Home = make_playpen(playpen, sb.st_size * 4); - if (!Home) - errx(1, "unable to make playpen for %lld bytes", (long long)sb.st_size * 4); - - where_to = Home; - /* Since we can call ourselves recursively, keep notes on where we came from */ - if (!getenv("_TOP")) - setenv("_TOP", Home, 1); - - if (unpack(pkg_fullname, extract)) { - warnx( - "unable to extract table of contents file from '%s' - not a package?", + sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME); + extract = extract_contents; + } + else { + extract = NULL; + sb.st_size = 100000; /* Make up a plausible average size */ + } + Home = make_playpen(playpen, sb.st_size * 4); + if (!Home) + errx(1, "unable to make playpen for %lld bytes", (long long)sb.st_size * 4); + where_to = Home; + /* Since we can call ourselves recursively, keep notes on where we came from */ + if (!getenv("_TOP")) + setenv("_TOP", Home, 1); + if (unpack(pkg_fullname, extract)) { + warnx( + "unable to extract table of contents file from '%s' - not a package?", pkg_fullname); - goto bomb; - } - - cfile = fopen(CONTENTS_FNAME, "r"); - if (!cfile) { - warnx( - "unable to open table of contents file '%s' - not a package?", - CONTENTS_FNAME); - goto bomb; - } - read_plist(&Plist, cfile); - fclose(cfile); + goto bomb; + } + cfile = fopen(CONTENTS_FNAME, "r"); + if (!cfile) { + warnx( + "unable to open table of contents file '%s' - not a package?", + CONTENTS_FNAME); + goto bomb; + } + read_plist(&Plist, cfile); + fclose(cfile); - /* Extract directly rather than moving? Oh goodie! */ - if (find_plist_option(&Plist, "extract-in-place")) { - if (Verbose) - printf("Doing in-place extraction for %s\n", pkg_fullname); - - p = find_plist(&Plist, PLIST_CWD); - if (p) { - if (!isdir(p->name) && !Fake) { - if (Verbose) - printf("Desired prefix of %s does not exist, creating..\n", p->name); - vsystem("/bin/mkdir -p %s", p->name); - if (chdir(p->name) == -1) { - warn("unable to change directory to '%s'", p->name); - goto bomb; - } - } - where_to = p->name; - inPlace = 1; - } - else { - warnx( - "no prefix specified in '%s' - this is a bad package!", - pkg_fullname); - goto bomb; - } + /* Extract directly rather than moving? Oh goodie! */ + if (find_plist_option(&Plist, "extract-in-place")) { + if (Verbose) + printf("Doing in-place extraction for %s\n", pkg_fullname); + p = find_plist(&Plist, PLIST_CWD); + if (p) { + if (!isdir(p->name) && !Fake) { + if (Verbose) + printf("Desired prefix of %s does not exist, creating..\n", p->name); + vsystem("/bin/mkdir -p %s", p->name); + if (chdir(p->name) == -1) { + warn("unable to change directory to '%s'", p->name); + goto bomb; } + } + where_to = p->name; + inPlace = 1; + } + else { + warnx( + "no prefix specified in '%s' - this is a bad package!", + pkg_fullname); + goto bomb; + } + } - /* - * Apply a crude heuristic to see how much space the package will - * take up once it's unpacked. I've noticed that most packages - * compress an average of 75%, so multiply by 4 for good measure. - */ + /* + * Apply a crude heuristic to see how much space the package will + * take up once it's unpacked. I've noticed that most packages + * compress an average of 75%, so multiply by 4 for good measure. + */ - if (!extract && !inPlace && min_free(playpen) < sb.st_size * 4) { - warnx("projected size of %lld exceeds available free space.\n" - "Please set your PKG_TMPDIR variable to point to a location with more\n" - "free space and try again", (long long)sb.st_size * 4); - warnx("not extracting %s\ninto %s, sorry!", - pkg_fullname, where_to); - goto bomb; + if (!extract && !inPlace && min_free(playpen) < sb.st_size * 4) { + warnx("projected size of %lld exceeds available free space.\n" +"Please set your PKG_TMPDIR variable to point to a location with more\n" + "free space and try again", (long long)sb.st_size * 4); + warnx("not extracting %s\ninto %s, sorry!", + pkg_fullname, where_to); + goto bomb; } /* If this is a direct extract and we didn't want it, stop now */ - if (inPlace && Fake) - goto success; + if (inPlace && Fake) + goto success; - /* Finally unpack the whole mess. If extract is null we - already + did so so don't bother doing it again. */ - if (extract && unpack(pkg_fullname, NULL)) { - warnx("unable to extract '%s'!", pkg_fullname); - goto bomb; - } + /* Finally unpack the whole mess. If extract is null we + already + did so so don't bother doing it again. */ + if (extract && unpack(pkg_fullname, NULL)) { + warnx("unable to extract '%s'!", pkg_fullname); + goto bomb; + } } - /* Check for sanity and dependencies */ - if (sanity_check(pkg)) - goto bomb; - - /* If we're running in MASTER mode, just output the plist and return */ - if (AddMode == MASTER) { - printf("%s\n", where_playpen()); - write_plist(&Plist, stdout); - return 0; - } + /* Check for sanity and dependencies */ + if (sanity_check(pkg)) + goto bomb; + + /* If we're running in MASTER mode, just output the plist and return */ + if (AddMode == MASTER) { + printf("%s\n", where_playpen()); + write_plist(&Plist, stdout); + return 0; } + } /* * If we have a prefix, delete the first one we see and add this * one in place of it. */ - if (Prefix) { - delete_plist(&Plist, FALSE, PLIST_CWD, NULL); - add_plist_top(&Plist, PLIST_CWD, Prefix); - } + if (Prefix) { + delete_plist(&Plist, FALSE, PLIST_CWD, NULL); + add_plist_top(&Plist, PLIST_CWD, Prefix); + } - setenv(PKG_PREFIX_VNAME, (p = find_plist(&Plist, PLIST_CWD)) ? p->name : ".", 1); - /* Protect against old packages with bogus @name and origin fields */ - if (Plist.name == NULL) - Plist.name = "anonymous"; - - if (Plist.origin == NULL) - Plist.origin = "anonymous/anonymous"; + setenv(PKG_PREFIX_VNAME, (p = find_plist(&Plist, PLIST_CWD)) ? p->name : ".", 1); + /* Protect against old packages with bogus @name and origin fields */ + if (Plist.name == NULL) + Plist.name = "anonymous"; + if (Plist.origin == NULL) + Plist.origin = "anonymous/anonymous"; - /* - * See if we're already registered either with the same name (the same - * version) or some other version with the same origin. - */ - if ((isinstalledpkg(Plist.name) > 0 || + /* + * See if we're already registered either with the same name (the same + * version) or some other version with the same origin. + */ + if ((isinstalledpkg(Plist.name) > 0 || matchbyorigin(Plist.origin, NULL) != NULL) && !Force) { - warnx("package '%s' or its older version already installed%s", - Plist.name, FailOnAlreadyInstalled ? "" : " (ignored)"); - code = FailOnAlreadyInstalled != FALSE; - goto success; /* close enough for government work */ >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807021741.m62HfuWN074750>