diff options
-rw-r--r-- | rpmio/rpmio.c | 37 | ||||
-rw-r--r-- | rpmio/url.c | 76 |
2 files changed, 34 insertions, 79 deletions
diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index 60c2c5c7d..7675d2378 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -21,11 +21,9 @@ extern int h_errno; #define IPPORT_HTTP 80 #endif -#include <rpm/argv.h> #include <rpm/rpmlog.h> #include <rpm/rpmmacro.h> #include <rpm/rpmfileutil.h> -#include <rpm/rpmstring.h> #include "rpmio/rpmio_internal.h" #include "rpmio/ugid.h" @@ -771,44 +769,31 @@ int ufdClose( void * cookie) * - better error checking + reporting * - curl & friends don't know about hkp://, transform to http? */ + static FD_t urlOpen(const char * url, int flags, mode_t mode) { - FD_t fd = NULL; - char *cmd = NULL; + FD_t fd; char *dest = NULL; - char *urlhelper = NULL; - int rc; - pid_t pid, wait; - - urlhelper = rpmExpand("%{?_urlhelper}", NULL); + int rc = 1; /* assume failure */ - dest = rpmGenPath(NULL, "%{_tmppath}/", "rpm-transfer.XXXXXX"); - close(mkstemp(dest)); - rasprintf(&cmd, "%s %s %s\n", urlhelper, dest, url); - urlhelper = _free(urlhelper); - - if ((pid = fork()) == 0) { - ARGV_t argv = NULL; - argvSplit(&argv, cmd, " "); - execvp(argv[0], (char *const *)argv); - exit(-1); /* error out if exec fails */ + fd = rpmMkTemp(NULL, &dest); + if (fd == NULL) { + return NULL; } - wait = waitpid(pid, &rc, 0); + Fclose(fd); - if (!WIFEXITED(rc) || WEXITSTATUS(rc)) { - rpmlog(RPMLOG_ERR, _("URL helper failed: %s (%d)\n"), - cmd, WEXITSTATUS(rc)); - } else { + rc = urlGetFile(url, dest); + if (rc == 0) { fd = fdOpen(dest, flags, mode); unlink(dest); + } else { + fd = NULL; } dest = _free(dest); - cmd = _free(cmd); return fd; } - static FD_t ufdOpen(const char * url, int flags, mode_t mode) { FD_t fd = NULL; diff --git a/rpmio/url.c b/rpmio/url.c index 2c90a6fb2..6fa2d1d6e 100644 --- a/rpmio/url.c +++ b/rpmio/url.c @@ -11,6 +11,8 @@ #include <rpm/rpmlog.h> #include <rpm/rpmurl.h> #include <rpm/rpmio.h> +#include <rpm/argv.h> +#include <rpm/rpmstring.h> #include "debug.h" @@ -244,69 +246,37 @@ int urlSplit(const char * url, urlinfo *uret) return 0; } + int urlGetFile(const char * url, const char * dest) { + char *cmd = NULL; + const char *target = NULL; + char *urlhelper = NULL; int rc; - FD_t sfd = NULL; - FD_t tfd = NULL; - const char * sfuPath = NULL; - int urlType = urlPath(url, &sfuPath); + pid_t pid, wait; - if (*sfuPath == '\0') - return FTPERR_UNKNOWN; - - sfd = Fopen(url, "r.ufdio"); - if (sfd == NULL || Ferror(sfd)) { - rpmlog(RPMLOG_ERR, _("failed to open %s: %s\n"), url, Fstrerror(sfd)); - rc = FTPERR_UNKNOWN; - goto exit; - } + urlhelper = rpmExpand("%{?_urlhelper}", NULL); if (dest == NULL) { - if ((dest = strrchr(sfuPath, '/')) != NULL) - dest++; - else - dest = sfuPath; + urlPath(url, &target); + } else { + target = dest; } - if (dest == NULL) - return FTPERR_UNKNOWN; - - tfd = Fopen(dest, "w.ufdio"); -if (_url_debug) -fprintf(stderr, "*** urlGetFile sfd %p %s tfd %p %s\n", sfd, url, (tfd ? tfd : NULL), dest); - if (tfd == NULL || Ferror(tfd)) { - /* XXX Fstrerror */ - rpmlog(RPMLOG_ERR, _("failed to create %s: %s\n"), dest, Fstrerror(tfd)); - rc = FTPERR_UNKNOWN; - goto exit; - } + /* XXX TODO: sanity checks like target == dest... */ - switch (urlType) { - case URL_IS_HTTPS: - case URL_IS_HTTP: - case URL_IS_HKP: - case URL_IS_FTP: - case URL_IS_PATH: - case URL_IS_DASH: - case URL_IS_UNKNOWN: - if ((rc = ufdGetFile(sfd, tfd))) { - (void) unlink(dest); - /* XXX FIXME: sfd possibly closed by copyData */ - (void) Fclose(sfd) ; - } - sfd = NULL; /* XXX Fclose(sfd) done by ufdGetFile */ - break; - default: - rc = FTPERR_UNKNOWN; - break; - } + rasprintf(&cmd, "%s %s %s\n", urlhelper, target, url); + urlhelper = _free(urlhelper); -exit: - if (tfd) - (void) Fclose(tfd); - if (sfd) - (void) Fclose(sfd); + if ((pid = fork()) == 0) { + ARGV_t argv = NULL; + argvSplit(&argv, cmd, " "); + execvp(argv[0], argv); + exit(-1); /* error out if exec fails */ + } + wait = waitpid(pid, &rc, 0); + cmd = _free(cmd); return rc; + } |