diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/misc.c | 13 | ||||
-rw-r--r-- | lib/misc.h | 2 | ||||
-rw-r--r-- | lib/query.c | 82 | ||||
-rw-r--r-- | lib/rpminstall.c | 185 | ||||
-rw-r--r-- | lib/url.c | 52 |
5 files changed, 196 insertions, 138 deletions
diff --git a/lib/misc.c b/lib/misc.c index fb2886413..e5053c156 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -649,7 +649,12 @@ int myGlobPatternP (const char *patternURL) return (0); } -int remoteGlob(const char * patterns, int * argcPtr, const char *** argvPtr) +static int glob_error(/*@unused@*/const char *foo, /*@unused@*/int bar) +{ + return 1; +} + +int rpmGlob(const char * patterns, int * argcPtr, const char *** argvPtr) { int ac = 0; const char ** av = NULL; @@ -675,14 +680,14 @@ int remoteGlob(const char * patterns, int * argcPtr, const char *** argvPtr) else argv = xrealloc(argv, (argc+2) * sizeof(*argv)); if (_debug) -fprintf(stderr, "*** remoteGlob argv[%d] \"%s\"\n", argc, av[j]); +fprintf(stderr, "*** rpmGlob argv[%d] \"%s\"\n", argc, av[j]); argv[argc++] = xstrdup(av[j]); continue; } gl.gl_pathc = 0; gl.gl_pathv = NULL; - rc = Glob(av[j], 0, NULL, &gl); + rc = Glob(av[j], 0, glob_error, &gl); if (rc) goto exit; @@ -724,7 +729,7 @@ fprintf(stderr, "*** GLOB maxb %d diskURL %d %*s globURL %p %s\n", maxb, nb, nb, while (*globFile == '/') globFile++; strcpy(globRoot, globFile); if (_debug) -fprintf(stderr, "*** remoteGlob argv[%d] \"%s\"\n", argc, globURL); +fprintf(stderr, "*** rpmGlob argv[%d] \"%s\"\n", argc, globURL); argv[argc++] = xstrdup(globURL); } Globfree(&gl); diff --git a/lib/misc.h b/lib/misc.h index 70cee1f95..b4f15c71c 100644 --- a/lib/misc.h +++ b/lib/misc.h @@ -41,7 +41,7 @@ void buildOrigFileList(Header h, /*@out@*/ const char *** fileListPtr, /*@out@*/ int * fileCountPtr); int myGlobPatternP (const char *patternURL); -int remoteGlob(const char * patterns, int * argcPtr, const char *** argvPtr); +int rpmGlob(const char * patterns, int * argcPtr, const char *** argvPtr); #ifdef __cplusplus } diff --git a/lib/query.c b/lib/query.c index 91ee65e8f..5e06fdfdb 100644 --- a/lib/query.c +++ b/lib/query.c @@ -454,61 +454,61 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, int retcode = 0; char *end = NULL; - switch (source) { + switch (source) { case RPMQV_RPM: - { int argc = 0; - const char ** argv = NULL; - int i; + { int argc = 0; + const char ** argv = NULL; + int i; - rc = remoteGlob(arg, &argc, &argv); - if (rc) - return 1; - for (i = 0; i < argc; i++) { - FD_t fd; - fd = Fopen(argv[i], "r.ufdio"); - if (Ferror(fd)) { - /* XXX Fstrerror */ - fprintf(stderr, _("open of %s failed: %s\n"), argv[i], + rc = rpmGlob(arg, &argc, &argv); + if (rc) + return 1; + for (i = 0; i < argc; i++) { + FD_t fd; + fd = Fopen(argv[i], "r.ufdio"); + if (Ferror(fd)) { + /* XXX Fstrerror */ + fprintf(stderr, _("open of %s failed: %s\n"), argv[i], #ifndef NOTYET urlStrerror(argv[i])); #else Fstrerror(fd)); #endif - if (fd) - Fclose(fd); - retcode = 1; - break; - } + if (fd) Fclose(fd); + retcode = 1; + break; + } - retcode = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL); + retcode = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL); - Fclose(fd); + Fclose(fd); - switch (retcode) { - case 0: - if (h == NULL) { - fprintf(stderr, _("old format source packages cannot " + switch (retcode) { + case 0: + if (h == NULL) { + fprintf(stderr, _("old format source packages cannot " "be queried\n")); + retcode = 1; + break; + } + retcode = showPackage(qva, db, h); + headerFree(h); + break; + case 1: + fprintf(stderr, _("%s does not appear to be a RPM package\n"), + argv[i]); + /*@fallthrough@*/ + case 2: + fprintf(stderr, _("query of %s failed\n"), argv[i]); retcode = 1; break; } - retcode = showPackage(qva, db, h); - headerFree(h); - break; - case 1: - fprintf(stderr, _("%s does not appear to be a RPM package\n"), argv[i]); - /*@fallthrough@*/ - case 2: - fprintf(stderr, _("query of %s failed\n"), argv[i]); - retcode = 1; - break; } - } - if (argv) { - for (i = 0; i < argc; i++) - xfree(argv[i]); - xfree(argv); - } + if (argv) { + for (i = 0; i < argc; i++) + xfree(argv[i]); + xfree(argv); + } } break; case RPMQV_SPECFILE: @@ -658,7 +658,7 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, dbiFreeIndexRecord(matches); } break; - } + } return retcode; } diff --git a/lib/rpminstall.c b/lib/rpminstall.c index 3dc5f731c..769f9c165 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -4,6 +4,8 @@ #include <rpmmacro.h> #include <rpmurl.h> +#include "misc.h" + static int hashesPrinted = 0; static void printHash(const unsigned long amount, const unsigned long total) { @@ -88,7 +90,7 @@ static void * showProgress(const Header h, const rpmCallbackType what, return rc; } -int rpmInstall(const char * rootdir, const char ** argv, int transFlags, +int rpmInstall(const char * rootdir, const char ** fileArgv, int transFlags, int interfaceFlags, int probFilter, rpmRelocation * relocations) { @@ -96,17 +98,17 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, FD_t fd; int i; int mode, rc, major; - const char ** pkgURL, ** tmppkgURL; + const char ** pkgURL = NULL; + const char ** tmppkgURL = NULL; const char ** fileURL; - int numPackages; - int numTmpPackages = 0, numBinaryPackages = 0, numSourcePackages = 0; + int numPkgs; + int numTmpPkgs = 0, numRPMS = 0, numSRPMS = 0; int numFailed = 0; Header h; int isSource; rpmTransactionSet rpmdep = NULL; int numConflicts; int stopInstall = 0; - size_t nb; int notifyFlags = interfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 ); int dbIsOpen = 0; const char ** sourceURL; @@ -122,74 +124,72 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, if (defaultReloc && !defaultReloc->newPath) defaultReloc = NULL; rpmMessage(RPMMESS_DEBUG, _("counting packages to install\n")); - for (fileURL = argv, numPackages = 0; *fileURL; fileURL++, numPackages++) + for (fileURL = fileArgv, numPkgs = 0; *fileURL; fileURL++, numPkgs++) ; - rpmMessage(RPMMESS_DEBUG, _("found %d packages\n"), numPackages); + rpmMessage(RPMMESS_DEBUG, _("found %d packages\n"), numPkgs); - nb = (numPackages + 1) * sizeof(char *); - pkgURL = alloca(nb); - memset(pkgURL, 0, nb); - tmppkgURL = alloca(nb); - memset(tmppkgURL, 0, nb); - nb = (numPackages + 1) * sizeof(Header); + pkgURL = xcalloc( (numPkgs + 1), sizeof(*pkgURL) ); + tmppkgURL = xcalloc( (numPkgs + 1), sizeof(*tmppkgURL) ); rpmMessage(RPMMESS_DEBUG, _("looking for packages to download\n")); - for (fileURL = argv, i = 0; *fileURL; fileURL++) { + for (fileURL = fileArgv, i = 0; *fileURL; fileURL++) { switch (urlIsURL(*fileURL)) { case URL_IS_FTP: case URL_IS_HTTP: { int myrc; + int j; const char *tfn; + const char ** argv; + int argc; - if (rpmIsVerbose()) - fprintf(stdout, _("Retrieving %s\n"), *fileURL); - -#ifdef DYING - { char tfnbuf[64]; - const char * tempfn; - strcpy(tfnbuf, "rpm-xfer.XXXXXX"); - /* XXX watchout for rootdir = NULL */ - tfn = tempfn = rpmGetPath("%{_tmppath}/", mktemp(tfnbuf), NULL); - switch(urlIsURL(tempfn)) { - case URL_IS_FTP: - case URL_IS_HTTP: - case URL_IS_DASH: - break; - case URL_IS_PATH: - tfn += sizeof("file://") - 1; - tfn = strchr(tfn, '/'); - /*@fallthrough@*/ - case URL_IS_UNKNOWN: - if (rootdir && rootdir[strlen(rootdir) - 1] == '/') - while (*tfn == '/') tfn++; - tfn = rpmGetPath( (rootdir ? rootdir : ""), tfn, NULL); - xfree(tempfn); - break; - } + myrc = rpmGlob(*fileURL, &argc, &argv); + if (myrc) { + rpmMessage(RPMMESS_ERROR, + _("skipping %s - rpmGlob failed(%d)\n"), + *fileURL, myrc); + numFailed++; + pkgURL[i] = NULL; + break; } -#else - { char tfnbuf[64]; - strcpy(tfnbuf, "rpm-xfer.XXXXXX"); - /*@-unrecog@*/ mktemp(tfnbuf) /*@=unrecog@*/; - tfn = rpmGenPath(rootdir, "%{_tmppath}/", tfnbuf); + if (argc > 1) { + numPkgs += argc - 1; + pkgURL = xrealloc(pkgURL, (numPkgs + 1) * sizeof(*pkgURL)); + tmppkgURL = xrealloc(tmppkgURL, (numPkgs + 1) * sizeof(*tmppkgURL)); } -#endif - /* XXX undefined %{name}/%{version}/%{release} here */ - /* XXX %{_tmpdir} does not exist */ - rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn); - myrc = urlGetFile(*fileURL, tfn); - if (myrc < 0) { - rpmMessage(RPMMESS_ERROR, + for (j = 0; j < argc; j++) { + + if (rpmIsVerbose()) + fprintf(stdout, _("Retrieving %s\n"), argv[j]); + + { char tfnbuf[64]; + strcpy(tfnbuf, "rpm-xfer.XXXXXX"); + /*@-unrecog@*/ mktemp(tfnbuf) /*@=unrecog@*/; + tfn = rpmGenPath(rootdir, "%{_tmppath}/", tfnbuf); + } + + /* XXX undefined %{name}/%{version}/%{release} here */ + /* XXX %{_tmpdir} does not exist */ + rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn); + myrc = urlGetFile(argv[j], tfn); + if (myrc < 0) { + rpmMessage(RPMMESS_ERROR, _("skipping %s - transfer failed - %s\n"), - *fileURL, ftpStrerror(myrc)); - numFailed++; - pkgURL[i] = NULL; - xfree(tfn); - } else { - tmppkgURL[numTmpPackages++] = pkgURL[i++] = tfn; + argv[j], ftpStrerror(myrc)); + numFailed++; + pkgURL[i] = NULL; + xfree(tfn); + } else { + tmppkgURL[numTmpPkgs++] = pkgURL[i++] = tfn; + } + } + if (argv) { + for (j = 0; j < argc; j++) + xfree(argv[j]); + xfree(argv); + argv = NULL; } } break; case URL_IS_PATH: @@ -201,7 +201,7 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, sourceURL = alloca(sizeof(*sourceURL) * i); - rpmMessage(RPMMESS_DEBUG, _("retrieved %d packages\n"), numTmpPackages); + rpmMessage(RPMMESS_DEBUG, _("retrieved %d packages\n"), numTmpPkgs); /* Build up the transaction set. As a special case, v1 source packages are installed right here, only because they don't have headers and @@ -211,9 +211,10 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, const char * fileName; (void) urlPath(*fileURL, &fileName); fd = Fopen(*fileURL, "r.ufdio"); - if (Ferror(fd)) { + if (fd == NULL || Ferror(fd)) { rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"), *fileURL, Fstrerror(fd)); + if (fd) Fclose(fd); numFailed++; pkgURL[i] = NULL; continue; @@ -235,7 +236,7 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, break; case 0: if (isSource) { - sourceURL[numSourcePackages++] = fileName; + sourceURL[numSRPMS++] = fileName; Fclose(fd); } else { if (!dbIsOpen) { @@ -253,21 +254,21 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, } if (defaultReloc) { - char ** paths; - char * name; + const char ** paths; int c; if (headerGetEntry(h, RPMTAG_PREFIXES, NULL, (void **) &paths, &c) && (c == 1)) { defaultReloc->oldPath = xstrdup(paths[0]); - free(paths); + xfree(paths); } else { - headerGetEntry(h, RPMTAG_NAME, NULL, (void **) &name, - NULL); + const char * name; + headerNVR(h, &name, NULL, NULL); rpmMessage(RPMMESS_ERROR, _("package %s is not relocateable\n"), name); - return numPackages; + goto errxit; + /*@notreached@*/ } } @@ -284,13 +285,13 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, case 1: rpmMessage(RPMMESS_ERROR, _("error reading from file %s\n"), *fileURL); - return numPackages; + goto errxit; /*@notreached@*/ break; case 2: rpmMessage(RPMMESS_ERROR, _("file %s requires a newer version of RPM\n"), *fileURL); - return numPackages; + goto errxit; /*@notreached@*/ break; } @@ -299,19 +300,19 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, defaultReloc->oldPath = NULL; } - numBinaryPackages++; + numRPMS++; } break; } } rpmMessage(RPMMESS_DEBUG, _("found %d source and %d binary packages\n"), - numSourcePackages, numBinaryPackages); + numSRPMS, numRPMS); - if (numBinaryPackages && !(interfaceFlags & INSTALL_NODEPS)) { + if (numRPMS && !(interfaceFlags & INSTALL_NODEPS)) { struct rpmDependencyConflict * conflicts; if (rpmdepCheck(rpmdep, &conflicts, &numConflicts)) { - numFailed = numPackages; + numFailed = numPkgs; stopInstall = 1; } @@ -319,19 +320,19 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, rpmMessage(RPMMESS_ERROR, _("failed dependencies:\n")); printDepProblems(stderr, conflicts, numConflicts); rpmdepFreeConflicts(conflicts, numConflicts); - numFailed = numPackages; + numFailed = numPkgs; stopInstall = 1; } } - if (numBinaryPackages && !(interfaceFlags & INSTALL_NOORDER)) { + if (numRPMS && !(interfaceFlags & INSTALL_NOORDER)) { if (rpmdepOrder(rpmdep)) { - numFailed = numPackages; + numFailed = numPkgs; stopInstall = 1; } } - if (numBinaryPackages && !stopInstall) { + if (numRPMS && !stopInstall) { rpmProblemSet probs = NULL; ; rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n")); @@ -339,8 +340,8 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, NULL, &probs, transFlags, probFilter); if (rc < 0) { - numFailed += numBinaryPackages; - } else if (rc) { + numFailed += numRPMS; + } else if (rc > 0) { numFailed += rc; rpmProblemSetPrint(stderr, probs); } @@ -348,14 +349,15 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, if (probs) rpmProblemSetFree(probs); } - if (numBinaryPackages) rpmtransFree(rpmdep); + if (numRPMS) rpmtransFree(rpmdep); - if (numSourcePackages && !stopInstall) { - for (i = 0; i < numSourcePackages; i++) { + if (numSRPMS && !stopInstall) { + for (i = 0; i < numSRPMS; i++) { fd = Fopen(sourceURL[i], "r.ufdio"); - if (Ferror(fd)) { + if (fd == NULL || Ferror(fd)) { rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"), sourceURL[i], Fstrerror(fd)); + if (fd) Fclose(fd); continue; } @@ -367,16 +369,29 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags, } } - for (i = 0; i < numTmpPackages; i++) { + for (i = 0; i < numTmpPkgs; i++) { Unlink(tmppkgURL[i]); xfree(tmppkgURL[i]); } + xfree(tmppkgURL); + xfree(pkgURL); /* FIXME how do we close our various fd's? */ if (dbIsOpen) rpmdbClose(db); return numFailed; + +errxit: + if (tmppkgURL) { + for (i = 0; i < numTmpPkgs; i++) + xfree(tmppkgURL[i]); + xfree(tmppkgURL); + } + if (pkgURL) + xfree(pkgURL); + if (dbIsOpen) rpmdbClose(db); + return numPkgs; } int rpmErase(const char * rootdir, const char ** argv, int transFlags, @@ -480,9 +495,9 @@ int rpmInstallSource(const char * rootdir, const char * arg, const char ** specF int rc; fd = Fopen(arg, "r.ufdio"); - if (Ferror(fd)) { + if (fd == NULL || Ferror(fd)) { rpmMessage(RPMMESS_ERROR, _("cannot open %s: %s\n"), arg, Fstrerror(fd)); - Fclose(fd); + if (fd) Fclose(fd); return 1; } @@ -112,7 +112,9 @@ DBGREFS(0, (stderr, "--> url %p -- %d %s at %s:%u\n", u, u->nrefs, msg, file, li FREE(u->password); FREE(u->host); FREE(u->portstr); +#ifdef DYING FREE(u->path); +#endif FREE(u->proxyu); FREE(u->proxyh); @@ -190,9 +192,10 @@ static void urlFind(urlinfo *uret, int mustAsk) else uCache = xmalloc(sizeof(*uCache)); } - uCache[i] = urlLink(u, "uCache (miss)"); + uCache[ucx] = urlLink(u, "uCache (miss)"); u = urlFree(u, "urlSplit (urlFind miss)"); } else { +#ifdef DYING /* XXX Swap original url and path into the cached structure */ const char *up = uCache[i]->path; ucx = i; @@ -201,12 +204,15 @@ static void urlFind(urlinfo *uret, int mustAsk) up = uCache[ucx]->url; uCache[ucx]->url = u->url; u->url = up; +#else + ucx = i; +#endif u = urlFree(u, "urlSplit (urlFind hit)"); } /* This URL is now cached. */ - u = urlLink(uCache[i], "uCache"); + u = urlLink(uCache[ucx], "uCache"); *uret = u; u = urlFree(u, "uCache (urlFind)"); @@ -378,7 +384,9 @@ int urlSplit(const char * url, urlinfo *uret) } /* Item was everything-but-path. Save path and continue parse on rest */ +#ifdef DYING u->path = xstrdup((*se ? se : "/")); +#endif *se = '\0'; break; } @@ -440,15 +448,27 @@ int urlGetFile(const char * url, const char * dest) { int rc; FD_t sfd = NULL; FD_t tfd = NULL; - urlinfo sfu; + const char * sfuPath = NULL; + int urlType = urlPath(url, &sfuPath); + if (*sfuPath == '\0') + return FTPERR_UNKNOWN; + sfd = Fopen(url, "r.ufdio"); if (sfd == NULL || Ferror(sfd)) { rpmMessage(RPMMESS_DEBUG, _("failed to open %s: %s\n"), url, Fstrerror(sfd)); - Fclose(sfd); +#ifdef DYING + if (sfd) + Fclose(sfd); return FTPERR_UNKNOWN; +#else + rc = FTPERR_UNKNOWN; + goto exit; +#endif } +#ifdef DYING + { urlinfo sfu; sfu = ufdGetUrlinfo(sfd); if (sfu != NULL && dest == NULL) { const char *fileName = sfu->path; @@ -461,6 +481,15 @@ int urlGetFile(const char * url, const char * dest) { (void) urlFree(sfu, "ufdGetUrlinfo (urlGetFile)"); sfu = NULL; } + } +#else + if (dest == NULL) { + if ((dest = strrchr(sfuPath, '/')) != NULL) + dest++; + else + dest = sfuPath; + } +#endif tfd = Fopen(dest, "w.ufdio"); if (_url_debug) @@ -468,14 +497,19 @@ fprintf(stderr, "*** urlGetFile sfd %p %s tfd %p %s\n", sfd, url, tfd, dest); if (tfd == NULL || Ferror(tfd)) { /* XXX Fstrerror */ rpmMessage(RPMMESS_DEBUG, _("failed to create %s: %s\n"), dest, Fstrerror(tfd)); +#ifdef DYING if (tfd) Fclose(tfd); if (sfd) Fclose(sfd); return FTPERR_UNKNOWN; +#else + rc = FTPERR_UNKNOWN; + goto exit; +#endif } - switch (urlIsURL(url)) { + switch (urlType) { case URL_IS_FTP: case URL_IS_HTTP: case URL_IS_PATH: @@ -486,14 +520,18 @@ fprintf(stderr, "*** urlGetFile sfd %p %s tfd %p %s\n", sfd, url, tfd, dest); /* XXX FIXME: sfd possibly closed by copyData */ /*@-usereleased@*/ Fclose(sfd) /*@=usereleased@*/ ; } - /* XXX Fclose(sfd) done by ufdCopy */ + sfd = NULL; /* XXX Fclose(sfd) done by ufdGetFile */ break; default: rc = FTPERR_UNKNOWN; break; } - Fclose(tfd); +exit: + if (tfd) + Fclose(tfd); + if (sfd) + Fclose(sfd); return rc; } |