From 81f604b4cb466193d4f5f93867f6d6c6a96cb12b Mon Sep 17 00:00:00 2001 From: ewt Date: Tue, 27 Feb 1996 17:37:06 +0000 Subject: [PATCH] added support for ftp style URL's on RPM command line CVS patchset: 430 CVS date: 1996/02/27 17:37:06 --- install.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/install.c b/install.c index 7fdb4e1..aac5738 100644 --- a/install.c +++ b/install.c @@ -3,6 +3,7 @@ #include #include +#include "ftp.h" #include "install.h" #include "lib/rpmlib.h" #include "messages.h" @@ -12,6 +13,7 @@ static int hashesPrinted = 0; static void printHash(const unsigned long amount, const unsigned long total); static void printPercent(const unsigned long amount, const unsigned long total); +static int getFtpURL(char * hostAndFile); static void printHash(const unsigned long amount, const unsigned long total) { int hashesNeeded; @@ -65,11 +67,22 @@ void doInstall(char * prefix, char * arg, int installFlags, int interfaceFlags) } message(MESS_DEBUG, "installing %s\n", arg); - fd = open(arg, O_RDONLY); - if (fd < 0) { - rpmdbClose(db); - fprintf(stderr, "error: cannot open %s\n", arg); - return; + + if (!strncmp(arg, "ftp://", 6)) { + if (isVerbose()) { + printf("Retrieving %s\n", arg); + } + fd = getFtpURL(arg + 6); + if (fd < 0) { + fprintf(stderr, "error: cannot ftp %s\n", arg); + } + } else { + fd = open(arg, O_RDONLY); + if (fd < 0) { + rpmdbClose(db); + fprintf(stderr, "error: cannot open %s\n", arg); + return; + } } if (interfaceFlags & RPMINSTALL_PERCENT) @@ -164,3 +177,52 @@ int doSourceInstall(char * prefix, char * arg, char ** specFile) { return rc; } + +static int getFtpURL(char * hostAndFile) { + char * buf; + char * chptr; + int ftpconn; + int fd; + char * tmp; + + message(MESS_DEBUG, "getting %s via anonymous ftp\n", hostAndFile); + + buf = alloca(strlen(hostAndFile) + 1); + strcpy(buf, hostAndFile); + + chptr = buf; + while (*chptr && (*chptr != '/')) chptr++; + if (!*chptr) return -1; + + *chptr = '\0'; + + ftpconn = ftpOpen(buf, NULL, NULL); + if (ftpconn < 0) return -1; + + *chptr = '/'; + + tmp = tmpnam(NULL); + fd = creat(tmp, 0600); + + if (fd < 0) { + unlink(tmp); + ftpClose(ftpconn); + return -1; + } + + if (ftpGetFile(ftpconn, chptr, fd)) { + unlink(tmp); + close(fd); + ftpClose(ftpconn); + return -1; + } + + ftpClose(ftpconn); + + close(fd); + fd = open(tmp, O_RDONLY); + + unlink(tmp); + + return fd; +} -- 2.7.4