diff options
| author | Jordan K. Hubbard <jkh@FreeBSD.org> | 1995-08-30 07:50:02 +0000 |
|---|---|---|
| committer | Jordan K. Hubbard <jkh@FreeBSD.org> | 1995-08-30 07:50:02 +0000 |
| commit | 3882688cee4ce55e06eba49dc887286a96e6bf20 (patch) | |
| tree | 28b5fe1178b4fa5256008c82a6de1a495509a92b /usr.sbin/pkg_install/lib | |
| parent | 4a053744bd0e5312ab87f7619310da9a2520293c (diff) | |
Notes
Diffstat (limited to 'usr.sbin/pkg_install/lib')
| -rw-r--r-- | usr.sbin/pkg_install/lib/Makefile | 2 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 107 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 5 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/msg.c | 4 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/pen.c | 55 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/plist.c | 4 |
6 files changed, 98 insertions, 79 deletions
diff --git a/usr.sbin/pkg_install/lib/Makefile b/usr.sbin/pkg_install/lib/Makefile index 3876b109c3a7..223a33d3ebae 100644 --- a/usr.sbin/pkg_install/lib/Makefile +++ b/usr.sbin/pkg_install/lib/Makefile @@ -1,5 +1,5 @@ LIB= install -SRCS= file.c msg.c plist.c str.c exec.c global.c pen.c +SRCS= file.c ftp.c msg.c plist.c str.c exec.c global.c pen.c CFLAGS+= ${DEBUG} NOPROFILE= yes NOPIC= yes diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index 29d969c59de1..6a81a8c3026c 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: file.c,v 1.9 1995/05/10 23:00:16 jkh Exp $"; +static const char *rcsid = "$Id: file.c,v 1.16 1995/08/01 09:49:27 jkh Exp $"; #endif /* @@ -23,14 +23,16 @@ static const char *rcsid = "$Id: file.c,v 1.9 1995/05/10 23:00:16 jkh Exp $"; */ #include "lib.h" -#include <FtpLibrary.h> +#include "ftp.h" #include <pwd.h> +#include <time.h> /* Quick check to see if a file exists */ Boolean fexists(char *fname) { - if (!access(fname, F_OK)) + struct stat dummy; + if (!lstat(fname, &dummy)) return TRUE; return FALSE; } @@ -70,6 +72,15 @@ isemptydir(char *fname) return FALSE; } +Boolean +isfile(char *fname) +{ + struct stat sb; + if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) + return TRUE; + return FALSE; +} + /* Check to see if file is a file and is empty. If nonexistent or not a file, say "it's empty", otherwise return TRUE if zero sized. */ Boolean @@ -151,52 +162,27 @@ fileURLFilename(char *fname, char *where, int max) return fname; } -/* - * Callback functions for fileGetURL - GetIO is called on I/O requests - * and GetAbort when the transfer aborts. - */ - -/* Something they can use to keep track of the action */ -Boolean connectionAborted = FALSE; - -static int -_fileGetIO(FTP *ftp, int n, char *s ) -{ - printf("In IO: %s\n", s); - return 0; -} - -static int -_fileGetAbort(FTP *ftp, int n, char *s ) -{ - /* No access or not found, exclude network or host unreachable */ - if (abs(n) == 550 && FtpBadReply550(s)) { - connectionAborted = TRUE; - return 1; - } - return 0; -} - #define HOSTNAME_MAX 64 - /* - * Try and fetch a file by URL, returning the name of the local - * copy if fetched successfully. + * Try and fetch a file by URL, returning the fd of open + * file if fetched successfully. */ char * fileGetURL(char *fname) { - static char out[FILENAME_MAX]; - char *cp; char host[HOSTNAME_MAX], file[FILENAME_MAX], dir[FILENAME_MAX]; - char pword[HOSTNAME_MAX + 40], *uname; + char pword[HOSTNAME_MAX + 40], *uname, *cp; + static char tmpl[40]; struct passwd *pw; - FTP *ftp; - int i; + FTP_t ftp; + int fd, fd2, i, len = 0; + char ch; + time_t start, stop; if (!isURL(fname)) return NULL; + ftp = FtpInit(); cp = fileURLHost(fname, host, HOSTNAME_MAX); if (!*cp) { whinge("URL `%s' has bad host part!", fname); @@ -209,10 +195,6 @@ fileGetURL(char *fname) return NULL; } - FtpSetErrorHandler(&FtpInit, _fileGetAbort); - FtpSetFlag(&FtpInit, FTP_REST); - FtpSetTimeout(&FtpInit, 60); /* XXX this may be too short */ - /* Maybe change to ftp if this doesn't work */ uname = "anonymous"; @@ -227,26 +209,43 @@ fileGetURL(char *fname) if (Verbose) printf("Trying to fetch %s from %s.\n", file, host); - FtpLogin(&ftp, host, uname, pword, NULL); + FtpOpen(ftp, host, uname, pword); + if (getenv("FTP_PASSIVE_MODE")) + FtpPassive(ftp, TRUE); strcpy(dir, file); for (i = strlen(dir); i && dir[i] != '/'; i--); dir[i] = '\0'; - if (dir[0]) + if (dir[0]) { + if (Verbose) printf("FTP: chdir to %s\n", dir); FtpChdir(ftp, dir); - FtpBinary(ftp); - + } + FtpBinary(ftp, TRUE); + if (Verbose) printf("FTP: trying to get %s\n", basename_of(file)); + fd = FtpGet(ftp, basename_of(file)); + if (fd < 0) + return NULL; if ((cp = getenv("PKG_TMPDIR")) != NULL) - sprintf(out, "%s/instpkg-XXXXXX.tgz", cp); + sprintf(tmpl, "%s/instpkg-XXXXXX.tgz", cp); else - strcpy(out, "/var/tmp/instpkg-XXXXXX.tgz"); - - FtpGet(ftp, basename_of(file), out); - FtpBye(ftp); - if (connectionAborted) + strcpy(tmpl, "/var/tmp/instpkg-XXXXXX.tgz"); + fd2 = mkstemp(tmpl); + if (fd2 < 0) { + whinge("Unable to create a temporary file for ftp: %s", tmpl); return NULL; - return out; + } + if (Verbose) printf("FTP: Trying to copy from ftp connection to temporary: %s\n", tmpl); + (void)time(&start); + while (read(fd, &ch, 1) == 1) { + ++len; + write(fd2, &ch, 1); + } + (void)time(&stop); + if (Verbose) printf("FTP: Read %d bytes from connection, %d elapsed seconds.\n%FTP: Average transfer rate: %d bytes/second.\n", len, stop - start, len / ((stop - start) + 1)); + FtpEOF(ftp); + FtpClose(ftp); + return tmpl; } char * @@ -255,7 +254,7 @@ fileFindByPath(char *fname) static char tmp[FILENAME_MAX]; char *cp; - if (fexists(fname)) { + if (fexists(fname) && isfile(fname)) { strcpy(tmp, fname); return tmp; } @@ -264,7 +263,7 @@ fileFindByPath(char *fname) char *cp2 = strsep(&cp, ":"); snprintf(tmp, FILENAME_MAX, "%s/%s.tgz", cp2 ? cp2 : cp, fname); - if (fexists(tmp)) + if (fexists(tmp) && isfile(fname)) return tmp; } return NULL; diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 61be709490e2..59f662a73f90 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,4 +1,4 @@ -/* $Id: lib.h,v 1.15 1995/04/22 13:58:43 jkh Exp $ */ +/* $Id: lib.h,v 1.18 1995/08/26 10:15:12 jkh Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -109,7 +109,7 @@ void cleanup(int); char *make_playpen(char *, size_t); void leave_playpen(void); char *where_playpen(void); -long min_free(char *); +size_t min_free(char *); /* String */ char *get_dash_string(char **); @@ -122,6 +122,7 @@ char *basename_of(char *); /* File */ Boolean fexists(char *); Boolean isdir(char *); +Boolean isfile(char *); Boolean isempty(char *); Boolean isURL(char *); char *fileGetURL(char *); diff --git a/usr.sbin/pkg_install/lib/msg.c b/usr.sbin/pkg_install/lib/msg.c index 460183e8a86e..edbce5f86ab9 100644 --- a/usr.sbin/pkg_install/lib/msg.c +++ b/usr.sbin/pkg_install/lib/msg.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: msg.c,v 1.4 1994/06/01 05:14:19 asami Exp $"; +static const char *rcsid = "$Id: msg.c,v 1.6 1995/08/26 10:15:15 jkh Exp $"; #endif /* @@ -99,5 +99,3 @@ y_or_n(Boolean def, const char *msg, ...) fclose(tty) ; return (ch == 'Y') ? TRUE : FALSE; } - - diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 37f36ce2ab93..bc03ef7b55ba 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.12 1995/04/22 13:58:44 jkh Exp $"; +static const char *rcsid = "$Id: pen.c,v 1.18 1995/08/28 14:47:30 jkh Exp $"; #endif /* @@ -30,6 +30,28 @@ static const char *rcsid = "$Id: pen.c,v 1.12 1995/04/22 13:58:44 jkh Exp $"; /* For keeping track of where we are */ 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 if ((stat("/usr/tmp", &sb) == SUCCESS | mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz) + strcpy(Pen, "/usr/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 @@ -38,31 +60,30 @@ static char Pen[FILENAME_MAX]; 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"); - } - else + if (!pen) + PlayPen = find_play_pen(sz); + else { strcpy(Pen, pen); + PlayPen = 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 (!sz) - fprintf(stderr, "Free temp space: %d bytes\n", min_free(Pen)); - else - fprintf(stderr, "Projected package size: %d bytes, free temp space: %d bytes\n", (int)sz, min_free(Pen)); + if (Verbose) + { + if (sz) + 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) barf("Can't chdir to '%s'.", Pen); @@ -97,7 +118,7 @@ where_playpen(void) return NULL; } -long +size_t min_free(char *tmpdir) { struct statfs buf; diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index cb6e4b7f50e4..36a016ccd751 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: plist.c,v 1.12 1995/04/22 07:41:02 jkh Exp $"; +static const char *rcsid = "$Id: plist.c,v 1.14 1995/07/28 01:50:35 ache Exp $"; #endif /* @@ -359,7 +359,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) if (p->type == PLIST_CWD) { Where = p->name; if (Verbose) - printf("Change working directory to %s\n", CMD_CHAR, Where); + printf("Change working directory to %s\n", Where); } else if (p->type == PLIST_UNEXEC) { char cmd[FILENAME_MAX]; |
