PERFORCE change 143703 for review

Anders Nore andenore at FreeBSD.org
Wed Jun 18 16:35:37 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=143703

Change 143703 by andenore at andenore_laptop on 2008/06/18 16:34:46

	Lot's of small changes, and syntax changes. Added a small initial man-
	page for pkg_convert. pkg_info has speed improvements for default
	behaviour and -W flag. pkg_{add, delete} adds and removes entries from
	the database cache so you don't have to run pkg_convert everytime you
	install og deinstall a package.

Affected files ...

.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#1 add
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/main.c#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/Makefile#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/converter.c#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/main.c#1 add
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#1 add
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/pkg_convert.1#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/main.c#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/delete/perform.c#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/Makefile#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/main.c#4 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/perform.c#4 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/deps.c#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/exec.c#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/global.c#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#4 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/match.c#4 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/str.c#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/Makefile#3 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/main.c#2 edit
.. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/perform.c#2 edit

Differences ...

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

@@ -98,237 +98,243 @@
 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];
+	if (*argv[0] != '/' && strchr(argv[0], '/') != NULL)
+		PkgAddCmd = realpath(argv[0], pkgaddpath);
+	else
+		PkgAddCmd = argv[0];
 
-    start = argv;
-    while ((ch = getopt(argc, argv, Options)) != -1) {
-	switch(ch) {
-	case 'v':
-	    Verbose++;
-	    break;
+	if(cacheExists()) {
+		printf("add.main(): cacheExists()\n");
+		openDatabase(PKG_DBCACHE_FILE);
+	}
 
-	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;
+	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;
+		}
 	}
-    }
-    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,
+		/* 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",
+							".tbz",
 #else
-			".tgz",
+							".tgz",
 #endif
-			sizeof(temppackageroot)) >= sizeof(temppackageroot))
-			errx(1, "package name too long");
+					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 (!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 (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);
 	}
-    }
-    /* 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);
+	/* 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("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("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 (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath))
-	>= sizeof(sitepath))
-	return NULL;
+	if (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath))
+		>= sizeof(sitepath))
+			return NULL;
 
-    uname(&u);
-    if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath))
-	return NULL;
+	uname(&u);
+	if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath))
+		return NULL;
 
-    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;
+	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#2 (text+ko) ====

@@ -38,18 +38,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,590 +63,678 @@
 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;
+	/* 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;
 	}
-	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 {
-	    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;
+		/* 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);
 		}
-		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?",
+		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?",
 		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;
+			/* 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;
+				}
 			}
-		    }
-		    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 */
+		warnx("package '%s' or its older version already installed%s",
+				  Plist.name, FailOnAlreadyInstalled ? "" : " (ignored)");
+		code = FailOnAlreadyInstalled != FALSE;
+		goto success;	/* close enough for government work */
     }
 
-    /* Now check the packing list for conflicts */
-    if (!IgnoreDeps){
-    for (p = Plist.head; p != NULL; p = p->next) {
-	if (p->type == PLIST_CONFLICTS) {
-	    int i;
-	    conflict[0] = strdup(p->name);
-	    conflict[1] = NULL;
-	    matched = matchinstalled(MATCH_GLOB, conflict, &errcode);
-	    free(conflict[0]);
-	    if (errcode == 0 && matched != NULL)
-		for (i = 0; matched[i] != NULL; i++)
-		    if (isinstalledpkg(matched[i]) > 0) {
-			warnx("package '%s' conflicts with %s", Plist.name,
-				matched[i]);
-			conflictsfound = 1;
-		    }
+	/* Now check the packing list for conflicts */
+	if (!IgnoreDeps) {
+		for (p = Plist.head; p != NULL; p = p->next) {
+			if (p->type == PLIST_CONFLICTS) {
+				int i;
+				conflict[0] = strdup(p->name);
+				conflict[1] = NULL;
+				matched = matchinstalled(MATCH_GLOB, conflict, &errcode);
+				free(conflict[0]);
+				if (errcode == 0 && matched != NULL)
+					for (i = 0; matched[i] != NULL; i++)
+						if (isinstalledpkg(matched[i]) > 0) {
+							warnx("package '%s' conflicts with %s", Plist.name,
+							matched[i]);
+							conflictsfound = 1;
+						}
+	
+					continue;
+			}
+	}
 
-	    continue;
+	if(conflictsfound) {
+		if(!Force) {
+			warnx("please use pkg_delete first to remove conflicting package(s) or -f to force installation");
+			code = 1;
+			goto bomb;
+		} else
+			warnx("-f specified; proceeding anyway");
 	}
-    }
-    if(conflictsfound) {
-	if(!Force) {
-	    warnx("please use pkg_delete first to remove conflicting package(s) or -f to force installation");
-	    code = 1;
-	    goto bomb;
-	} else
-	    warnx("-f specified; proceeding anyway");
-    }
 
-    /* Now check the packing list for dependencies */
-    for (p = Plist.head; p ; p = p->next) {
-	char *deporigin;
+	/* Now check the packing list for dependencies */
+	for (p = Plist.head; p ; p = p->next) {
+		char *deporigin;
 
-	if (p->type != PLIST_PKGDEP)
-	    continue;
-	deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL;
-	if (Verbose) {
-	    printf("Package '%s' depends on '%s'", Plist.name, p->name);
-	    if (deporigin != NULL)
-		printf(" with '%s' origin", deporigin);
-	    printf(".\n");
-	}
-	if (isinstalledpkg(p->name) <= 0 &&
-	    !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) {
-	    char path[FILENAME_MAX], *cp = NULL;
+		if (p->type != PLIST_PKGDEP)
+			continue;
+		
+		deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL;
+		if (Verbose) {
+			printf("Package '%s' depends on '%s'", Plist.name, p->name);
+			if (deporigin != NULL)
+				printf(" with '%s' origin", deporigin);
+			printf(".\n");
+		}
+		
+		if (isinstalledpkg(p->name) <= 0 &&
+			!(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) {
+				char path[FILENAME_MAX], *cp = NULL;
 
-	    if (!Fake) {
-		char prefixArg[2 + MAXPATHLEN]; /* "-P" + Prefix */
-		if (PrefixRecursive) {
-		    strlcpy(prefixArg, "-P", sizeof(prefixArg));
-		    strlcat(prefixArg, Prefix, sizeof(prefixArg));
-		}
-		if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) {
-		    const char *ext;
+			if (!Fake) {
+				char prefixArg[2 + MAXPATHLEN]; /* "-P" + Prefix */
+				if (PrefixRecursive) {
+					strlcpy(prefixArg, "-P", sizeof(prefixArg));
+					strlcat(prefixArg, Prefix, sizeof(prefixArg));
+				}
+				
+				if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) {
+					const char *ext;
 
-		    ext = strrchr(pkg_fullname, '.');
-		    if (ext == NULL)
+					ext = strrchr(pkg_fullname, '.');
+					if (ext == NULL)
 #if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
-			ext = ".tbz";
+				ext = ".tbz";
 #else
-			ext = ".tgz";
+				ext = ".tgz";
 #endif
-		    snprintf(path, FILENAME_MAX, "%s/%s%s", getenv("_TOP"), p->name, ext);
-		    if (fexists(path))
-			cp = path;
-		    else
-			cp = fileFindByPath(pkg, p->name);
-		    if (cp) {

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


More information about the p4-projects mailing list