use the --use-compress-program argument to tar and do away with

the file descriptor handling mess in lib/file.c.

also use --fast-read where applicable.

result of pkg_info -B on 1.5ghz pentium4, linux:

			before		after
mozilla-1.4nb1.tgz	1.96sec		0.04sec
mozilla-1.4nb1.tbz	18.66sec	0.21sec

866mhz pentium3, NetBSD:

			before		after
mozilla-1.4nb1.tgz	2.22sec		0.07sec
mozilla-1.4nb1.tbz	16.29sec	0.34sec

-rw-r--r--    1 grant    users    13816195 Dec 20 13:59 mozilla-1.4nb1.tbz
-rw-r--r--    1 grant    users    15814227 Dec 20 13:58 mozilla-1.4nb1.tgz

XXX fetches over ftp/http still read the whole file.
This commit is contained in:
grant 2003-12-20 03:31:56 +00:00
parent 683625bd0a
commit dd46f97f58
5 changed files with 47 additions and 108 deletions

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.90 2003/12/20 00:47:18 grant Exp $ */
/* $NetBSD: perform.c,v 1.91 2003/12/20 03:31:56 grant Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.90 2003/12/20 00:47:18 grant Exp $");
__RCSID("$NetBSD: perform.c,v 1.91 2003/12/20 03:31:56 grant Exp $");
#endif
#endif
@ -110,7 +110,7 @@ pkg_do(const char *pkg)
int replacing = 0;
char *where_to;
char dbdir[FILENAME_MAX];
const char *exact, *extra1, *extra2;
const char *exact, *extra1;
FILE *cfile;
int errc;
plist_t *p;
@ -176,11 +176,10 @@ pkg_do(const char *pkg)
goto bomb;
}
}
extra1 = "--fast-read";
extra2 = CONTENTS_FNAME;
extra1 = CONTENTS_FNAME;
} else {
/* some values for stdin */
extra1 = extra2 = NULL;
extra1 = NULL;
sb.st_size = 100000; /* Make up a plausible average size */
}
Home = make_playpen(playpen, sizeof(playpen), sb.st_size * 4);
@ -188,7 +187,7 @@ pkg_do(const char *pkg)
warnx("unable to make playpen for %ld bytes",
(long) (sb.st_size * 4));
where_to = Home;
if (unpack(pkg, extra1, extra2)) {
if (unpack(pkg, extra1)) {
warnx("unable to extract table of contents file from `%s' - not a package?",
pkg);
goto bomb;
@ -249,7 +248,7 @@ pkg_do(const char *pkg)
goto success;
/* Finally unpack the whole mess */
if (unpack(pkg, NULL, NULL)) {
if (unpack(pkg, NULL)) {
warnx("unable to extract `%s'!", pkg);
goto bomb;
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.50 2003/09/23 09:36:06 wiz Exp $ */
/* $NetBSD: perform.c,v 1.51 2003/12/20 03:31:56 grant Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.50 2003/09/23 09:36:06 wiz Exp $");
__RCSID("$NetBSD: perform.c,v 1.51 2003/12/20 03:31:56 grant Exp $");
#endif
#endif
@ -106,7 +106,7 @@ pkg_do(char *pkg)
goto bail;
}
Home = make_playpen(PlayPen, PlayPenSize, sb.st_size / 2);
if (unpack(fname, "+*", NULL)) {
if (unpack(fname, ALL_FNAMES)) {
warnx("error during unpacking, no info for '%s' available", pkg);
code = 1;
goto bail;

View File

@ -1,11 +1,11 @@
/* $NetBSD: file.c,v 1.69 2003/11/21 22:04:32 wiz Exp $ */
/* $NetBSD: file.c,v 1.70 2003/12/20 03:31:56 grant Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
#else
__RCSID("$NetBSD: file.c,v 1.69 2003/11/21 22:04:32 wiz Exp $");
__RCSID("$NetBSD: file.c,v 1.70 2003/12/20 03:31:56 grant Exp $");
#endif
#endif
@ -558,107 +558,41 @@ remove_files(const char *path, const char *pattern)
* Unpack a tar file
*/
int
unpack(const char *pkg, const char *extra1, const char *extra2)
unpack(const char *pkg, const char *flist)
{
const char *decompress_cmd[3];
char args[10] = "-";
char cmd[FILENAME_MAX];
const char *decompress_cmd;
const char *suf;
int pipefds[2];
pid_t tarpid, gzpid;
int state;
int ret;
if (!IS_STDIN(pkg)) {
suf = suffix_of(pkg);
if (!strcmp(suf, "tbz") || !strcmp(suf, "bz2")) {
decompress_cmd[0] = BZIP2_CMD;
decompress_cmd[1] = "-c";
decompress_cmd[2] = "-d";
}
else if (!strcmp(suf, "tgz") || !strcmp(suf, "gz")) {
decompress_cmd[0] = GZIP_CMD;
decompress_cmd[1] = "-c";
decompress_cmd[2] = "-d";
}
else if (!strcmp(suf, "tar")) {
decompress_cmd[0] = "cat";
decompress_cmd[1] = NULL;
decompress_cmd[2] = NULL;
}
if (!strcmp(suf, "tbz") || !strcmp(suf, "bz2"))
decompress_cmd = BZIP2_CMD;
else if (!strcmp(suf, "tgz") || !strcmp(suf, "gz"))
decompress_cmd = GZIP_CMD;
else if (!strcmp(suf, "tar"))
; /* do nothing */
else
errx(EXIT_FAILURE, "don't know how to decompress %s, sorry", pkg);
} else {
decompress_cmd[0] = GZIP_CMD;
decompress_cmd[1] = "-c";
decompress_cmd[2] = "-d";
}
} else
decompress_cmd = GZIP_CMD;
/* Set up a pipe for passing the extracted contents, and fork off a decompress process. */
if (pipe(pipefds) == -1) {
warnx("cannot create pipe -- %s extract of %s failed!", TAR_CMD, pkg);
strlcat(args, "xpf", sizeof(args));
sprintf(cmd, "%s %s %s %s %s %s %s", TAR_CMD,
flist ? "--fast-read" : "",
decompress_cmd != NULL ? "--use-compress-program" : "",
decompress_cmd != NULL ? decompress_cmd : "", args, pkg,
flist ? flist : "");
if (Verbose)
printf("running: %s\n", cmd);
if (system(cmd) != 0) {
warnx("extract of %s failed", pkg);
return 1;
}
if ((gzpid = fork()) == -1) {
warnx("cannot fork process for %s -- %s extract of %s failed!",
decompress_cmd[0], TAR_CMD, pkg);
return 1;
}
if (gzpid == 0) { /* The child */
if (dup2(pipefds[1], STDOUT_FILENO) == -1) {
warnx("dup2 failed before executing %s command",
decompress_cmd[0]);
_exit(2);
}
close(pipefds[0]);
close(pipefds[1]);
if (decompress_cmd[1] != NULL)
execlp(decompress_cmd[0], decompress_cmd[0],
decompress_cmd[1], decompress_cmd[2],
pkg, NULL);
else
execlp(decompress_cmd[0], decompress_cmd[0],
pkg, NULL);
warnx("failed to execute %s command", decompress_cmd[0]);
_exit(2);
}
/* Meanwhile, back in the parent process ... */
/* fork off an untar process */
if ((tarpid = fork()) == -1) {
warnx("cannot fork process for %s -- %s extract of %s failed!",
TAR_CMD, TAR_CMD, pkg);
return 1;
}
if (tarpid == 0) { /* The child */
if (dup2(pipefds[0], STDIN_FILENO) == -1) {
warnx("dup2 failed before executing %s command",
TAR_CMD);
_exit(2);
}
close(pipefds[0]);
close(pipefds[1]);
execlp(TAR_CMD, TAR_CMD, "-xpf", "-", extra1, extra2, NULL);
warnx("failed to execute %s command", TAR_CMD);
_exit(2);
}
close(pipefds[0]);
close(pipefds[1]);
ret = 0;
/* wait for decompress process ... */
if (waitpid(gzpid, &state, 0) < 0) {
/* error has been reported by child */
ret = 1;
}
/* ... and for tar exit so we are sure the needed files exist */
if (waitpid(tarpid, &state, 0) < 0) {
/* error has been reported by child */
ret = 1;
}
return ret;
return 0;
}
/*

View File

@ -1,8 +1,8 @@
/* $NetBSD: ftpio.c,v 1.61 2003/12/20 02:37:49 grant Exp $ */
/* $NetBSD: ftpio.c,v 1.62 2003/12/20 03:31:56 grant Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: ftpio.c,v 1.61 2003/12/20 02:37:49 grant Exp $");
__RCSID("$NetBSD: ftpio.c,v 1.62 2003/12/20 03:31:56 grant Exp $");
#endif
/*-
@ -1062,7 +1062,7 @@ http_fetch(const char *url, const char *path)
if ((path != NULL) && (chdir(path) < 0))
_exit(127);
if (unpack("-", Verbose ? "-vv" : NULL, NULL) != 0) {
if (unpack("-", NULL) != 0) {
warnx("unpack failed");
_exit(2);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: lib.h,v 1.64 2003/12/20 00:47:19 grant Exp $ */
/* $NetBSD: lib.h,v 1.65 2003/12/20 03:31:56 grant Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@ -115,6 +115,12 @@
#define VIEWS_FNAME "+VIEWS"
#define DEPOT_FNAME "+DEPOT"
/*
* files which we expect to be in every package, passed to
* tar --fast-read.
*/
#define ALL_FNAMES CONTENTS_FNAME" "COMMENT_FNAME" "DESC_FNAME" "MTREE_FNAME" "BUILD_VERSION_FNAME" "BUILD_INFO_FNAME" "SIZE_PKG_FNAME" "SIZE_ALL_FNAME
#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
/* The name of the "prefix" environment variable given to scripts */
@ -258,7 +264,7 @@ void copy_file(char *, char *, char *);
void move_file(char *, char *, char *);
void remove_files(const char *, const char *);
int delete_hierarchy(char *, Boolean, Boolean);
int unpack(const char *, const char *, const char *);
int unpack(const char *, const char *);
void format_cmd(char *, size_t, char *, char *, char *);
/* ftpio.c: FTP handling */