diff options
author | jkh <jkh@FreeBSD.org> | 1995-08-17 00:36:06 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1995-08-17 00:36:06 +0000 |
commit | f9c6f6c7f4f081ee9748d9268ea672d0e7b0c98a (patch) | |
tree | a2a17b322d58cfb605922fcd39bc609d21162676 /usr.sbin/pkg_install | |
parent | 49de37c88791929bc81b67219fd52e735ac677fb (diff) | |
download | FreeBSD-src-f9c6f6c7f4f081ee9748d9268ea672d0e7b0c98a.zip FreeBSD-src-f9c6f6c7f4f081ee9748d9268ea672d0e7b0c98a.tar.gz |
Some fixes to make this "TMPDIR agile".
Submitted by: jmacd + some of my own fixes.
Diffstat (limited to 'usr.sbin/pkg_install')
-rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 12 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/pen.c | 46 |
2 files changed, 38 insertions, 20 deletions
diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index b3c31cc..7438edd 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: perform.c,v 1.27 1995/07/30 09:11:20 jkh Exp $"; +static const char *rcsid = "$Id: perform.c,v 1.28 1995/08/06 03:20:01 jkh Exp $"; #endif /* @@ -117,7 +117,11 @@ pkg_do(char *pkg) strcpy(pkg_fullname, tmp); } } - Home = make_playpen(PlayPen, 0); + if (stat(pkg_fullname, &sb) == FAIL) { + whinge("Can't stat package file '%s'.", pkg_fullname); + goto bomb; + } + Home = make_playpen(PlayPen, sb.st_size * 4); where_to = PlayPen; sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME); if (unpack(pkg_fullname, extract_contents)) { @@ -171,10 +175,6 @@ pkg_do(char *pkg) * 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 (stat(pkg_fullname, &sb) == FAIL) { - whinge("Can't stat package file '%s'.", pkg_fullname); - goto bomb; - } if (min_free(where_to) < sb.st_size * 4) { whinge("Projected size of %d exceeds available free space.\nPlease set your PKG_TMPDIR variable to point to a location with more\nfree space and try again.", sb.st_size * 4); diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 2786721..febf265 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: pen.c,v 1.13 1995/04/26 07:43:35 jkh Exp $"; +static const char *rcsid = "$Id: pen.c,v 1.14 1995/08/06 03:21:04 jkh Exp $"; #endif /* @@ -32,6 +32,25 @@ static char Cwd[FILENAME_MAX]; static char Pen[FILENAME_MAX]; extern char *PlayPen; +/* Find a good place to play. */ +static char * +find_play_pen(size_t sz) +{ + char *cp; + struct stat sb; + + if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) + sprintf(Pen, "%s/instmp.XXXXXX", cp); + else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) + sprintf(Pen, "%s/instmp.XXXXXX", cp); + else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz) + strcpy(Pen, "/var/tmp/instmp.XXXXXX"); + else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz) + strcpy(Pen, "/tmp/instmp.XXXXXX"); + else barf("Can't find enough temporary space to extract the files, please set\nyour PKG_TMPDIR environment variable to a location with at least %d bytes\nfree.", sz); + return Pen; +} + /* * Make a temporary directory to play in and chdir() to it, returning * pathname of previous working directory. @@ -39,32 +58,31 @@ extern char *PlayPen; char * make_playpen(char *pen, size_t sz) { - if (!pen) { - char *cp; - - if ((cp = getenv("PKG_TMPDIR")) != NULL) - sprintf(Pen, "%s/instmp.XXXXXX", cp); - else - strcpy(Pen, "/var/tmp/instmp.XXXXXX"); + if (!pen) + PlayPen = find_play_pen(sz); + else { + strcpy(Pen, pen); PlayPen = Pen; } - else - strcpy(Pen, pen); if (!getcwd(Cwd, FILENAME_MAX)) upchuck("getcwd"); if (!mktemp(Pen)) barf("Can't mktemp '%s'.", Pen); if (mkdir(Pen, 0755) == FAIL) barf("Can't mkdir '%s'.", Pen); - if (Verbose) { + if (Verbose) + { if (!sz) - fprintf(stderr, "Free temp space: %d bytes\n", min_free(Pen)); + fprintf(stderr, "Free temp space: %d bytes in %s\n", min_free(Pen), Pen); else - fprintf(stderr, "Projected package size: %d bytes, free temp space: %d bytes\n", (int)sz, min_free(Pen)); + fprintf(stderr, "Projected package size: %d bytes, +free temp space: %d bytes in %s\n", (int)sz, min_free(Pen), Pen); } if (min_free(Pen) < sz) { rmdir(Pen); - barf("Not enough free space to create `%s'.\nPlease set your PKG_TMPDIR environment variable to a location with more space and\ntry the command again.", Pen); + barf("Not enough free space to create `%s'.\nPlease set your PKG_TMPDIR +environment variable to a location with more space and\ntry the command +again.", Pen); PlayPen = NULL; } if (chdir(Pen) == FAIL) |