Some fixes to make this "TMPDIR agile".

Submitted by:	jmacd + some of my own fixes.
This commit is contained in:
Jordan K. Hubbard 1995-08-17 00:36:06 +00:00
parent a16b708542
commit 3122afe4bd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=10085
2 changed files with 38 additions and 20 deletions

View File

@ -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);

View File

@ -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)