Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

lib/rpminstall.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include <rpmcli.h>
00008 
00009 #include "rpmdb.h"
00010 #include "rpmds.h"
00011 
00012 #define _RPMTS_INTERNAL         /* ts->goal, ts->dbmode, ts->suggests */
00013 #include "rpmts.h"
00014 
00015 #include "manifest.h"
00016 #include "misc.h"       /* XXX for rpmGlob() */
00017 #include "debug.h"
00018 
00019 /*@access rpmts @*/     /* XXX ts->goal, ts->dbmode */
00020 /*@access IDTX @*/
00021 /*@access IDT @*/
00022 
00023 /*@unchecked@*/
00024 int rpmcliPackagesTotal = 0;
00025 /*@unchecked@*/
00026 int rpmcliHashesCurrent = 0;
00027 /*@unchecked@*/
00028 int rpmcliHashesTotal = 0;
00029 /*@unchecked@*/
00030 int rpmcliProgressCurrent = 0;
00031 /*@unchecked@*/
00032 int rpmcliProgressTotal = 0;
00033 
00040 static void printHash(const unsigned long amount, const unsigned long total)
00041         /*@globals rpmcliHashesCurrent, rpmcliHashesTotal,
00042                 rpmcliProgressCurrent, fileSystem @*/
00043         /*@modifies rpmcliHashesCurrent, rpmcliHashesTotal,
00044                 rpmcliProgressCurrent, fileSystem @*/
00045 {
00046     int hashesNeeded;
00047 
00048     rpmcliHashesTotal = (isatty (STDOUT_FILENO) ? 44 : 50);
00049 
00050     if (rpmcliHashesCurrent != rpmcliHashesTotal) {
00051 /*@+relaxtypes@*/
00052         float pct = (total ? (((float) amount) / total) : 1.0);
00053         hashesNeeded = (rpmcliHashesTotal * pct) + 0.5;
00054 /*@=relaxtypes@*/
00055         while (hashesNeeded > rpmcliHashesCurrent) {
00056             if (isatty (STDOUT_FILENO)) {
00057                 int i;
00058                 for (i = 0; i < rpmcliHashesCurrent; i++)
00059                     (void) putchar ('#');
00060                 for (; i < rpmcliHashesTotal; i++)
00061                     (void) putchar (' ');
00062                 fprintf(stdout, "(%3d%%)", (int)((100 * pct) + 0.5));
00063                 for (i = 0; i < (rpmcliHashesTotal + 6); i++)
00064                     (void) putchar ('\b');
00065             } else
00066                 fprintf(stdout, "#");
00067 
00068             rpmcliHashesCurrent++;
00069         }
00070         (void) fflush(stdout);
00071 
00072         if (rpmcliHashesCurrent == rpmcliHashesTotal) {
00073             int i;
00074             rpmcliProgressCurrent++;
00075             if (isatty(STDOUT_FILENO)) {
00076                 for (i = 1; i < rpmcliHashesCurrent; i++)
00077                     (void) putchar ('#');
00078 /*@+relaxtypes@*/
00079                 pct = (rpmcliProgressTotal
00080                     ? (((float) rpmcliProgressCurrent) / rpmcliProgressTotal)
00081                     : 1);
00082 /*@=relaxtypes@*/
00083                 fprintf(stdout, " [%3d%%]", (int)((100 * pct) + 0.5));
00084             }
00085             fprintf(stdout, "\n");
00086         }
00087         (void) fflush(stdout);
00088     }
00089 }
00090 
00091 void * rpmShowProgress(/*@null@*/ const void * arg,
00092                         const rpmCallbackType what,
00093                         const unsigned long amount,
00094                         const unsigned long total,
00095                         /*@null@*/ fnpyKey key,
00096                         /*@null@*/ void * data)
00097         /*@globals rpmcliHashesCurrent, rpmcliProgressCurrent, rpmcliProgressTotal,
00098                 fileSystem @*/
00099         /*@modifies rpmcliHashesCurrent, rpmcliProgressCurrent, rpmcliProgressTotal,
00100                 fileSystem @*/
00101 {
00102 /*@-abstract -castexpose @*/
00103     Header h = (Header) arg;
00104 /*@=abstract =castexpose @*/
00105     char * s;
00106     int flags = (int) ((long)data);
00107     void * rc = NULL;
00108 /*@-abstract -assignexpose @*/
00109     const char * filename = (const char *)key;
00110 /*@=abstract =assignexpose @*/
00111     static FD_t fd = NULL;
00112     int xx;
00113 
00114     switch (what) {
00115     case RPMCALLBACK_INST_OPEN_FILE:
00116 /*@-boundsread@*/
00117         if (filename == NULL || filename[0] == '\0')
00118             return NULL;
00119 /*@=boundsread@*/
00120         fd = Fopen(filename, "r.ufdio");
00121         /*@-type@*/ /* FIX: still necessary? */
00122         if (fd == NULL || Ferror(fd)) {
00123             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), filename,
00124                         Fstrerror(fd));
00125             if (fd != NULL) {
00126                 xx = Fclose(fd);
00127                 fd = NULL;
00128             }
00129         } else
00130             fd = fdLink(fd, "persist (showProgress)");
00131         /*@=type@*/
00132 /*@+voidabstract@*/
00133         return (void *)fd;
00134 /*@=voidabstract@*/
00135         /*@notreached@*/ break;
00136 
00137     case RPMCALLBACK_INST_CLOSE_FILE:
00138         /*@-type@*/ /* FIX: still necessary? */
00139         fd = fdFree(fd, "persist (showProgress)");
00140         /*@=type@*/
00141         if (fd != NULL) {
00142             xx = Fclose(fd);
00143             fd = NULL;
00144         }
00145         break;
00146 
00147     case RPMCALLBACK_INST_START:
00148         rpmcliHashesCurrent = 0;
00149         if (h == NULL || !(flags & INSTALL_LABEL))
00150             break;
00151         /* @todo Remove headerSprintf() on a progress callback. */
00152         if (flags & INSTALL_HASH) {
00153             s = headerSprintf(h, "%{NAME}",
00154                                 rpmTagTable, rpmHeaderFormats, NULL);
00155             if (isatty (STDOUT_FILENO))
00156                 fprintf(stdout, "%4d:%-23.23s", rpmcliProgressCurrent + 1, s);
00157             else
00158                 fprintf(stdout, "%-28.28s", s);
00159             (void) fflush(stdout);
00160             s = _free(s);
00161         } else {
00162             s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}",
00163                                   rpmTagTable, rpmHeaderFormats, NULL);
00164             fprintf(stdout, "%s\n", s);
00165             (void) fflush(stdout);
00166             s = _free(s);
00167         }
00168         break;
00169 
00170     case RPMCALLBACK_TRANS_PROGRESS:
00171     case RPMCALLBACK_INST_PROGRESS:
00172 /*@+relaxtypes@*/
00173         if (flags & INSTALL_PERCENT)
00174             fprintf(stdout, "%%%% %f\n", (double) (total
00175                                 ? ((((float) amount) / total) * 100)
00176                                 : 100.0));
00177         else if (flags & INSTALL_HASH)
00178             printHash(amount, total);
00179 /*@=relaxtypes@*/
00180         (void) fflush(stdout);
00181         break;
00182 
00183     case RPMCALLBACK_TRANS_START:
00184         rpmcliHashesCurrent = 0;
00185         rpmcliProgressTotal = 1;
00186         rpmcliProgressCurrent = 0;
00187         if (!(flags & INSTALL_LABEL))
00188             break;
00189         if (flags & INSTALL_HASH)
00190             fprintf(stdout, "%-28s", _("Preparing..."));
00191         else
00192             fprintf(stdout, "%s\n", _("Preparing packages for installation..."));
00193         (void) fflush(stdout);
00194         break;
00195 
00196     case RPMCALLBACK_TRANS_STOP:
00197         if (flags & INSTALL_HASH)
00198             printHash(1, 1);    /* Fixes "preparing..." progress bar */
00199         rpmcliProgressTotal = rpmcliPackagesTotal;
00200         rpmcliProgressCurrent = 0;
00201         break;
00202 
00203     case RPMCALLBACK_REPACKAGE_START:
00204         rpmcliHashesCurrent = 0;
00205         rpmcliProgressTotal = total;
00206         rpmcliProgressCurrent = 0;
00207         if (!(flags & INSTALL_LABEL))
00208             break;
00209         if (flags & INSTALL_HASH)
00210             fprintf(stdout, "%-28s\n", _("Repackaging..."));
00211         else
00212             fprintf(stdout, "%s\n", _("Repackaging erased files..."));
00213         (void) fflush(stdout);
00214         break;
00215 
00216     case RPMCALLBACK_REPACKAGE_PROGRESS:
00217         if (amount && (flags & INSTALL_HASH))
00218             printHash(1, 1);    /* Fixes "preparing..." progress bar */
00219         break;
00220 
00221     case RPMCALLBACK_REPACKAGE_STOP:
00222         rpmcliProgressTotal = total;
00223         rpmcliProgressCurrent = total;
00224         if (flags & INSTALL_HASH)
00225             printHash(1, 1);    /* Fixes "preparing..." progress bar */
00226         rpmcliProgressTotal = rpmcliPackagesTotal;
00227         rpmcliProgressCurrent = 0;
00228         if (!(flags & INSTALL_LABEL))
00229             break;
00230         if (flags & INSTALL_HASH)
00231             fprintf(stdout, "%-28s\n", _("Upgrading..."));
00232         else
00233             fprintf(stdout, "%s\n", _("Upgrading packages..."));
00234         (void) fflush(stdout);
00235         break;
00236 
00237     case RPMCALLBACK_UNINST_PROGRESS:
00238         break;
00239     case RPMCALLBACK_UNINST_START:
00240         break;
00241     case RPMCALLBACK_UNINST_STOP:
00242         break;
00243     case RPMCALLBACK_UNPACK_ERROR:
00244         break;
00245     case RPMCALLBACK_CPIO_ERROR:
00246         break;
00247     case RPMCALLBACK_UNKNOWN:
00248     default:
00249         break;
00250     }
00251 
00252     return rc;
00253 }       
00254 
00255 typedef /*@only@*/ /*@null@*/ const char * str_t;
00256 
00257 struct rpmEIU {
00258     Header h;
00259     FD_t fd;
00260     int numFailed;
00261     int numPkgs;
00262 /*@only@*/
00263     str_t * pkgURL;
00264 /*@dependent@*/ /*@null@*/
00265     str_t * fnp;
00266 /*@only@*/
00267     char * pkgState;
00268     int prevx;
00269     int pkgx;
00270     int numRPMS;
00271     int numSRPMS;
00272 /*@only@*/ /*@null@*/
00273     str_t * sourceURL;
00274     int isSource;
00275     int argc;
00276 /*@only@*/ /*@null@*/
00277     str_t * argv;
00278 /*@dependent@*/
00279     rpmRelocation * relocations;
00280     rpmRC rpmrc;
00281 };
00282 
00284 /*@-bounds@*/
00285 int rpmInstall(rpmts ts,
00286                 struct rpmInstallArguments_s * ia,
00287                 const char ** fileArgv)
00288 {
00289     struct rpmEIU * eiu = memset(alloca(sizeof(*eiu)), 0, sizeof(*eiu));
00290     rpmps ps;
00291     rpmprobFilterFlags probFilter;
00292     rpmRelocation * relocations;
00293 /*@only@*/ /*@null@*/ const char * fileURL = NULL;
00294     int stopInstall = 0;
00295     const char ** av = NULL;
00296     rpmVSFlags vsflags, ovsflags, tvsflags;
00297     int ac = 0;
00298     int rc;
00299     int xx;
00300     int i;
00301 
00302     if (fileArgv == NULL) goto exit;
00303 
00304     ts->goal = TSM_INSTALL;
00305     rpmcliPackagesTotal = 0;
00306 
00307     if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
00308         ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
00309 
00310     (void) rpmtsSetFlags(ts, ia->transFlags);
00311     probFilter = ia->probFilter;
00312     relocations = ia->relocations;
00313 
00314     if (ia->installInterfaceFlags & INSTALL_UPGRADE)
00315         vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
00316     else
00317         vsflags = rpmExpandNumeric("%{?_vsflags_install}");
00318     if (ia->qva_flags & VERIFY_DIGEST)
00319         vsflags |= _RPMVSF_NODIGESTS;
00320     if (ia->qva_flags & VERIFY_SIGNATURE)
00321         vsflags |= _RPMVSF_NOSIGNATURES;
00322     if (ia->qva_flags & VERIFY_HDRCHK)
00323         vsflags |= RPMVSF_NOHDRCHK;
00324     ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
00325 
00326     {   int notifyFlags;
00327         notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
00328         xx = rpmtsSetNotifyCallback(ts,
00329                         rpmShowProgress, (void *) ((long)notifyFlags));
00330     }
00331 
00332     if ((eiu->relocations = relocations) != NULL) {
00333         while (eiu->relocations->oldPath)
00334             eiu->relocations++;
00335         if (eiu->relocations->newPath == NULL)
00336             eiu->relocations = NULL;
00337     }
00338 
00339     /* Build fully globbed list of arguments in argv[argc]. */
00340     /*@-branchstate@*/
00341     /*@-temptrans@*/
00342     for (eiu->fnp = fileArgv; *eiu->fnp != NULL; eiu->fnp++) {
00343     /*@=temptrans@*/
00344         av = _free(av); ac = 0;
00345         rc = rpmGlob(*eiu->fnp, &ac, &av);
00346         if (rc || ac == 0) {
00347             rpmError(RPMERR_OPEN, _("File not found by glob: %s\n"), *eiu->fnp);
00348             continue;
00349         }
00350 
00351         eiu->argv = xrealloc(eiu->argv, (eiu->argc+ac+1) * sizeof(*eiu->argv));
00352         memcpy(eiu->argv+eiu->argc, av, ac * sizeof(*av));
00353         eiu->argc += ac;
00354         eiu->argv[eiu->argc] = NULL;
00355     }
00356     /*@=branchstate@*/
00357     av = _free(av);     ac = 0;
00358 
00359 restart:
00360     /* Allocate sufficient storage for next set of args. */
00361     if (eiu->pkgx >= eiu->numPkgs) {
00362         eiu->numPkgs = eiu->pkgx + eiu->argc;
00363         eiu->pkgURL = xrealloc(eiu->pkgURL,
00364                         (eiu->numPkgs + 1) * sizeof(*eiu->pkgURL));
00365         memset(eiu->pkgURL + eiu->pkgx, 0,
00366                         ((eiu->argc + 1) * sizeof(*eiu->pkgURL)));
00367         eiu->pkgState = xrealloc(eiu->pkgState,
00368                         (eiu->numPkgs + 1) * sizeof(*eiu->pkgState));
00369         memset(eiu->pkgState + eiu->pkgx, 0,
00370                         ((eiu->argc + 1) * sizeof(*eiu->pkgState)));
00371     }
00372 
00373     /* Retrieve next set of args, cache on local storage. */
00374     for (i = 0; i < eiu->argc; i++) {
00375         fileURL = _free(fileURL);
00376         fileURL = eiu->argv[i];
00377         eiu->argv[i] = NULL;
00378 
00379 #ifdef  NOTYET
00380 if (fileURL[0] == '=') {
00381     rpmds this = rpmdsSingle(RPMTAG_REQUIRENAME, fileURL+1, NULL, 0);
00382 
00383     xx = rpmtsSolve(ts, this, NULL);
00384     if (ts->suggests && ts->nsuggests > 0) {
00385         fileURL = _free(fileURL);
00386         fileURL = ts->suggests[0];
00387         ts->suggests[0] = NULL;
00388         while (ts->nsuggests-- > 0) {
00389             if (ts->suggests[ts->nsuggests] == NULL)
00390                 continue;
00391             ts->suggests[ts->nsuggests] = _free(ts->suggests[ts->nsuggests]);
00392         }
00393         ts->suggests = _free(ts->suggests);
00394         rpmMessage(RPMMESS_DEBUG, _("Adding goal: %s\n"), fileURL);
00395         eiu->pkgURL[eiu->pkgx] = fileURL;
00396         fileURL = NULL;
00397         eiu->pkgx++;
00398     }
00399     this = rpmdsFree(this);
00400 } else
00401 #endif
00402 
00403         switch (urlIsURL(fileURL)) {
00404         case URL_IS_FTP:
00405         case URL_IS_HTTP:
00406         {   const char *tfn;
00407 
00408             if (rpmIsVerbose())
00409                 fprintf(stdout, _("Retrieving %s\n"), fileURL);
00410 
00411             {   char tfnbuf[64];
00412                 const char * rootDir = rpmtsRootDir(ts);
00413                 if (!(rootDir && * rootDir))
00414                     rootDir = "";
00415                 strcpy(tfnbuf, "rpm-xfer.XXXXXX");
00416                 (void) mktemp(tfnbuf);
00417                 tfn = rpmGenPath(rootDir, "%{_tmppath}/", tfnbuf);
00418             }
00419 
00420             /* XXX undefined %{name}/%{version}/%{release} here */
00421             /* XXX %{_tmpdir} does not exist */
00422             rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn);
00423             rc = urlGetFile(fileURL, tfn);
00424             if (rc < 0) {
00425                 rpmMessage(RPMMESS_ERROR,
00426                         _("skipping %s - transfer failed - %s\n"),
00427                         fileURL, ftpStrerror(rc));
00428                 eiu->numFailed++;
00429                 eiu->pkgURL[eiu->pkgx] = NULL;
00430                 tfn = _free(tfn);
00431                 /*@switchbreak@*/ break;
00432             }
00433             eiu->pkgState[eiu->pkgx] = 1;
00434             eiu->pkgURL[eiu->pkgx] = tfn;
00435             eiu->pkgx++;
00436         }   /*@switchbreak@*/ break;
00437         case URL_IS_PATH:
00438         default:
00439             eiu->pkgURL[eiu->pkgx] = fileURL;
00440             fileURL = NULL;
00441             eiu->pkgx++;
00442             /*@switchbreak@*/ break;
00443         }
00444     }
00445     fileURL = _free(fileURL);
00446 
00447     if (eiu->numFailed) goto exit;
00448 
00449     /* Continue processing file arguments, building transaction set. */
00450     for (eiu->fnp = eiu->pkgURL+eiu->prevx;
00451          *eiu->fnp != NULL;
00452          eiu->fnp++, eiu->prevx++)
00453     {
00454         const char * fileName;
00455 
00456         rpmMessage(RPMMESS_DEBUG, "============== %s\n", *eiu->fnp);
00457         (void) urlPath(*eiu->fnp, &fileName);
00458 
00459         /* Try to read the header from a package file. */
00460         eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
00461         if (eiu->fd == NULL || Ferror(eiu->fd)) {
00462             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
00463                         Fstrerror(eiu->fd));
00464             if (eiu->fd != NULL) {
00465                 xx = Fclose(eiu->fd);
00466                 eiu->fd = NULL;
00467             }
00468             eiu->numFailed++; *eiu->fnp = NULL;
00469             continue;
00470         }
00471 
00472         /* Read the header, verifying signatures (if present). */
00473         tvsflags = rpmtsSetVSFlags(ts, vsflags);
00474         eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
00475         tvsflags = rpmtsSetVSFlags(ts, tvsflags);
00476         xx = Fclose(eiu->fd);
00477         eiu->fd = NULL;
00478 
00479         switch (eiu->rpmrc) {
00480         case RPMRC_FAIL:
00481             rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *eiu->fnp);
00482             eiu->numFailed++; *eiu->fnp = NULL;
00483             continue;
00484             /*@notreached@*/ /*@switchbreak@*/ break;
00485         case RPMRC_NOTFOUND:
00486             goto maybe_manifest;
00487             /*@notreached@*/ /*@switchbreak@*/ break;
00488         case RPMRC_NOTTRUSTED:
00489         case RPMRC_NOKEY:
00490         case RPMRC_OK:
00491         default:
00492             /*@switchbreak@*/ break;
00493         }
00494 
00495         eiu->isSource = headerIsEntry(eiu->h, RPMTAG_SOURCEPACKAGE);
00496 
00497         if (eiu->isSource) {
00498             rpmMessage(RPMMESS_DEBUG, _("\tadded source package [%d]\n"),
00499                 eiu->numSRPMS);
00500             eiu->sourceURL = xrealloc(eiu->sourceURL,
00501                                 (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL));
00502             eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp;
00503             *eiu->fnp = NULL;
00504             eiu->numSRPMS++;
00505             eiu->sourceURL[eiu->numSRPMS] = NULL;
00506             continue;
00507         }
00508 
00509         if (eiu->relocations) {
00510             const char ** paths;
00511             int pft;
00512             int c;
00513 
00514             if (headerGetEntry(eiu->h, RPMTAG_PREFIXES, &pft,
00515                                        (void **) &paths, &c) && (c == 1))
00516             {
00517                 eiu->relocations->oldPath = xstrdup(paths[0]);
00518                 paths = headerFreeData(paths, pft);
00519             } else {
00520                 const char * name;
00521                 xx = headerNVR(eiu->h, &name, NULL, NULL);
00522                 rpmMessage(RPMMESS_ERROR,
00523                                _("package %s is not relocatable\n"), name);
00524                 eiu->numFailed++;
00525                 goto exit;
00526                 /*@notreached@*/
00527             }
00528         }
00529 
00530         /* On --freshen, verify package is installed and newer */
00531         if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
00532             rpmdbMatchIterator mi;
00533             const char * name;
00534             Header oldH;
00535             int count;
00536 
00537             xx = headerNVR(eiu->h, &name, NULL, NULL);
00538             mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0);
00539             count = rpmdbGetIteratorCount(mi);
00540             while ((oldH = rpmdbNextIterator(mi)) != NULL) {
00541                 if (rpmVersionCompare(oldH, eiu->h) < 0)
00542                     /*@innercontinue@*/ continue;
00543                 /* same or newer package already installed */
00544                 count = 0;
00545                 /*@innerbreak@*/ break;
00546             }
00547             mi = rpmdbFreeIterator(mi);
00548             if (count == 0) {
00549                 eiu->h = headerFree(eiu->h);
00550                 continue;
00551             }
00552             /* Package is newer than those currently installed. */
00553         }
00554 
00555         /*@-abstract@*/
00556         rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName,
00557                         (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
00558                         relocations);
00559         /*@=abstract@*/
00560 
00561         /* XXX reference held by transaction set */
00562         eiu->h = headerFree(eiu->h);
00563         if (eiu->relocations)
00564             eiu->relocations->oldPath = _free(eiu->relocations->oldPath);
00565 
00566         switch(rc) {
00567         case 0:
00568             rpmMessage(RPMMESS_DEBUG, _("\tadded binary package [%d]\n"),
00569                         eiu->numRPMS);
00570             /*@switchbreak@*/ break;
00571         case 1:
00572             rpmMessage(RPMMESS_ERROR,
00573                             _("error reading from file %s\n"), *eiu->fnp);
00574             eiu->numFailed++;
00575             goto exit;
00576             /*@notreached@*/ /*@switchbreak@*/ break;
00577         case 2:
00578             rpmMessage(RPMMESS_ERROR,
00579                             _("file %s requires a newer version of RPM\n"),
00580                             *eiu->fnp);
00581             eiu->numFailed++;
00582             goto exit;
00583             /*@notreached@*/ /*@switchbreak@*/ break;
00584         }
00585 
00586         eiu->numRPMS++;
00587         continue;
00588 
00589 maybe_manifest:
00590         /* Try to read a package manifest. */
00591         eiu->fd = Fopen(*eiu->fnp, "r.fpio");
00592         if (eiu->fd == NULL || Ferror(eiu->fd)) {
00593             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
00594                         Fstrerror(eiu->fd));
00595             if (eiu->fd != NULL) {
00596                 xx = Fclose(eiu->fd);
00597                 eiu->fd = NULL;
00598             }
00599             eiu->numFailed++; *eiu->fnp = NULL;
00600             break;
00601         }
00602 
00603         /* Read list of packages from manifest. */
00604 /*@-nullstate@*/ /* FIX: *eiu->argv can be NULL */
00605         rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv);
00606 /*@=nullstate@*/
00607         if (rc != RPMRC_OK)
00608             rpmError(RPMERR_MANIFEST, _("%s: not an rpm package (or package manifest): %s\n"),
00609                         *eiu->fnp, Fstrerror(eiu->fd));
00610         xx = Fclose(eiu->fd);
00611         eiu->fd = NULL;
00612 
00613         /* If successful, restart the query loop. */
00614         if (rc == RPMRC_OK) {
00615             eiu->prevx++;
00616             goto restart;
00617         }
00618 
00619         eiu->numFailed++; *eiu->fnp = NULL;
00620         break;
00621     }
00622 
00623     rpmMessage(RPMMESS_DEBUG, _("found %d source and %d binary packages\n"),
00624                 eiu->numSRPMS, eiu->numRPMS);
00625 
00626     if (eiu->numFailed) goto exit;
00627 
00628     if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) {
00629 
00630         if (rpmtsCheck(ts)) {
00631             eiu->numFailed = eiu->numPkgs;
00632             stopInstall = 1;
00633         }
00634 
00635         ps = rpmtsProblems(ts);
00636         if (!stopInstall && rpmpsNumProblems(ps) > 0) {
00637             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
00638             rpmpsPrint(NULL, ps);
00639             eiu->numFailed = eiu->numPkgs;
00640             stopInstall = 1;
00641 
00642             /*@-branchstate@*/
00643             if (ts->suggests != NULL && ts->nsuggests > 0) {
00644                 rpmMessage(RPMMESS_NORMAL, _("    Suggested resolutions:\n"));
00645                 for (i = 0; i < ts->nsuggests; i++) {
00646                     const char * str = ts->suggests[i];
00647 
00648                     if (str == NULL)
00649                         break;
00650 
00651                     rpmMessage(RPMMESS_NORMAL, "\t%s\n", str);
00652                 
00653                     ts->suggests[i] = NULL;
00654                     str = _free(str);
00655                 }
00656                 ts->suggests = _free(ts->suggests);
00657             }
00658             /*@=branchstate@*/
00659         }
00660         ps = rpmpsFree(ps);
00661     }
00662 
00663     if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
00664         if (rpmtsOrder(ts)) {
00665             eiu->numFailed = eiu->numPkgs;
00666             stopInstall = 1;
00667         }
00668     }
00669 
00670     if (eiu->numRPMS && !stopInstall) {
00671 
00672         rpmcliPackagesTotal += eiu->numSRPMS;
00673 
00674         rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n"));
00675 
00676         /* Drop added/available package indices and dependency sets. */
00677         rpmtsClean(ts);
00678 
00679         rc = rpmtsRun(ts, NULL, probFilter);
00680         ps = rpmtsProblems(ts);
00681 
00682         if (rc < 0) {
00683             eiu->numFailed += eiu->numRPMS;
00684         } else if (rc > 0) {
00685             eiu->numFailed += rc;
00686             if (rpmpsNumProblems(ps) > 0)
00687                 rpmpsPrint(stderr, ps);
00688         }
00689         ps = rpmpsFree(ps);
00690     }
00691 
00692     if (eiu->numSRPMS && !stopInstall) {
00693         if (eiu->sourceURL != NULL)
00694         for (i = 0; i < eiu->numSRPMS; i++) {
00695             if (eiu->sourceURL[i] == NULL) continue;
00696             eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio");
00697             if (eiu->fd == NULL || Ferror(eiu->fd)) {
00698                 rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"),
00699                            eiu->sourceURL[i], Fstrerror(eiu->fd));
00700                 if (eiu->fd != NULL) {
00701                     xx = Fclose(eiu->fd);
00702                     eiu->fd = NULL;
00703                 }
00704                 continue;
00705             }
00706 
00707             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
00708                 eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL);
00709                 if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++;
00710             }
00711 
00712             xx = Fclose(eiu->fd);
00713             eiu->fd = NULL;
00714         }
00715     }
00716 
00717 exit:
00718     if (eiu->pkgURL != NULL)
00719     for (i = 0; i < eiu->numPkgs; i++) {
00720         if (eiu->pkgURL[i] == NULL) continue;
00721         if (eiu->pkgState[i] == 1)
00722             (void) Unlink(eiu->pkgURL[i]);
00723         eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
00724     }
00725     eiu->pkgState = _free(eiu->pkgState);
00726     eiu->pkgURL = _free(eiu->pkgURL);
00727     eiu->argv = _free(eiu->argv);
00728 
00729     rpmtsEmpty(ts);
00730 
00731     return eiu->numFailed;
00732 }
00733 /*@=bounds@*/
00734 
00735 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
00736                 const char ** argv)
00737 {
00738     int count;
00739     const char ** arg;
00740     int numFailed = 0;
00741     int stopUninstall = 0;
00742     int numPackages = 0;
00743     rpmVSFlags vsflags, ovsflags;
00744     rpmps ps;
00745 
00746     if (argv == NULL) return 0;
00747 
00748     vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
00749     if (ia->qva_flags & VERIFY_DIGEST)
00750         vsflags |= _RPMVSF_NODIGESTS;
00751     if (ia->qva_flags & VERIFY_SIGNATURE)
00752         vsflags |= _RPMVSF_NOSIGNATURES;
00753     if (ia->qva_flags & VERIFY_HDRCHK)
00754         vsflags |= RPMVSF_NOHDRCHK;
00755     ovsflags = rpmtsSetVSFlags(ts, vsflags);
00756 
00757     if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
00758         ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
00759 
00760     (void) rpmtsSetFlags(ts, ia->transFlags);
00761 
00762 #ifdef  NOTYET  /* XXX no callbacks on erase yet */
00763     {   int notifyFlags;
00764         notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
00765         xx = rpmtsSetNotifyCallback(ts,
00766                         rpmShowProgress, (void *) ((long)notifyFlags)
00767     }
00768 #endif
00769 
00770     ts->goal = TSM_ERASE;
00771 
00772     for (arg = argv; *arg; arg++) {
00773         rpmdbMatchIterator mi;
00774 
00775         /* XXX HACK to get rpmdbFindByLabel out of the API */
00776         mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
00777         if (mi == NULL) {
00778             rpmMessage(RPMMESS_ERROR, _("package %s is not installed\n"), *arg);
00779             numFailed++;
00780         } else {
00781             Header h;   /* XXX iterator owns the reference */
00782             count = 0;
00783             while ((h = rpmdbNextIterator(mi)) != NULL) {
00784                 unsigned int recOffset = rpmdbGetIteratorOffset(mi);
00785 
00786                 if (!(count++ == 0 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES))) {
00787                     rpmMessage(RPMMESS_ERROR, _("\"%s\" specifies multiple packages\n"),
00788                         *arg);
00789                     numFailed++;
00790                     /*@innerbreak@*/ break;
00791                 }
00792                 if (recOffset) {
00793                     (void) rpmtsAddEraseElement(ts, h, recOffset);
00794                     numPackages++;
00795                 }
00796             }
00797         }
00798         mi = rpmdbFreeIterator(mi);
00799     }
00800 
00801     if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) {
00802 
00803         if (rpmtsCheck(ts)) {
00804             numFailed = numPackages;
00805             stopUninstall = 1;
00806         }
00807 
00808         ps = rpmtsProblems(ts);
00809         if (!stopUninstall && rpmpsNumProblems(ps) > 0) {
00810             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
00811             rpmpsPrint(NULL, ps);
00812             numFailed += numPackages;
00813             stopUninstall = 1;
00814         }
00815         ps = rpmpsFree(ps);
00816     }
00817 
00818 #ifdef  NOTYET
00819     if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
00820         if (rpmtsOrder(ts)) {
00821             numFailed += numPackages;
00822             stopUninstall = 1;
00823         }
00824     }
00825 #endif
00826 
00827     if (!stopUninstall) {
00828         (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE));
00829 
00830         /* Drop added/available package indices and dependency sets. */
00831         rpmtsClean(ts);
00832 
00833         numPackages = rpmtsRun(ts, NULL, 0);
00834         ps = rpmtsProblems(ts);
00835         if (rpmpsNumProblems(ps) > 0)
00836             rpmpsPrint(NULL, ps);
00837         numFailed += numPackages;
00838         stopUninstall = 1;
00839         ps = rpmpsFree(ps);
00840     }
00841 
00842     rpmtsEmpty(ts);
00843 
00844     return numFailed;
00845 }
00846 
00847 int rpmInstallSource(rpmts ts, const char * arg,
00848                 const char ** specFilePtr, const char ** cookie)
00849 {
00850     FD_t fd;
00851     int rc;
00852 
00853 
00854     fd = Fopen(arg, "r.ufdio");
00855     if (fd == NULL || Ferror(fd)) {
00856         rpmMessage(RPMMESS_ERROR, _("cannot open %s: %s\n"), arg, Fstrerror(fd));
00857         if (fd != NULL) (void) Fclose(fd);
00858         return 1;
00859     }
00860 
00861     if (rpmIsVerbose())
00862         fprintf(stdout, _("Installing %s\n"), arg);
00863 
00864     {
00865         rpmVSFlags ovsflags =
00866                 rpmtsSetVSFlags(ts, (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD));
00867         rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie);
00868         rc = (rpmrc == RPMRC_OK ? 0 : 1);
00869         ovsflags = rpmtsSetVSFlags(ts, ovsflags);
00870     }
00871     if (rc != 0) {
00872         rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), arg);
00873         /*@-unqualifiedtrans@*/
00874         if (specFilePtr && *specFilePtr)
00875             *specFilePtr = _free(*specFilePtr);
00876         if (cookie && *cookie)
00877             *cookie = _free(*cookie);
00878         /*@=unqualifiedtrans@*/
00879     }
00880 
00881     (void) Fclose(fd);
00882 
00883     return rc;
00884 }
00885 
00886 /*@unchecked@*/
00887 static int reverse = -1;
00888 
00891 static int IDTintcmp(const void * a, const void * b)
00892         /*@*/
00893 {
00894     /*@-castexpose@*/
00895     return ( reverse * (((IDT)a)->val.u32 - ((IDT)b)->val.u32) );
00896     /*@=castexpose@*/
00897 }
00898 
00899 IDTX IDTXfree(IDTX idtx)
00900 {
00901     if (idtx) {
00902         int i;
00903         if (idtx->idt)
00904         for (i = 0; i < idtx->nidt; i++) {
00905             IDT idt = idtx->idt + i;
00906             idt->h = headerFree(idt->h);
00907             idt->key = _free(idt->key);
00908         }
00909         idtx->idt = _free(idtx->idt);
00910         idtx = _free(idtx);
00911     }
00912     return NULL;
00913 }
00914 
00915 IDTX IDTXnew(void)
00916 {
00917     IDTX idtx = xcalloc(1, sizeof(*idtx));
00918     idtx->delta = 10;
00919     idtx->size = sizeof(*((IDT)0));
00920     return idtx;
00921 }
00922 
00923 IDTX IDTXgrow(IDTX idtx, int need)
00924 {
00925     if (need < 0) return NULL;
00926     if (idtx == NULL)
00927         idtx = IDTXnew();
00928     if (need == 0) return idtx;
00929 
00930     if ((idtx->nidt + need) > idtx->alloced) {
00931         while (need > 0) {
00932             idtx->alloced += idtx->delta;
00933             need -= idtx->delta;
00934         }
00935         idtx->idt = xrealloc(idtx->idt, (idtx->alloced * idtx->size) );
00936     }
00937     return idtx;
00938 }
00939 
00940 IDTX IDTXsort(IDTX idtx)
00941 {
00942     if (idtx != NULL && idtx->idt != NULL && idtx->nidt > 0)
00943         qsort(idtx->idt, idtx->nidt, idtx->size, IDTintcmp);
00944     return idtx;
00945 }
00946 
00947 IDTX IDTXload(rpmts ts, rpmTag tag)
00948 {
00949     IDTX idtx = NULL;
00950     rpmdbMatchIterator mi;
00951     HGE_t hge = (HGE_t) headerGetEntry;
00952     Header h;
00953 
00954     /*@-branchstate@*/
00955     mi = rpmtsInitIterator(ts, tag, NULL, 0);
00956 #ifdef  NOTYET
00957     (void) rpmdbSetIteratorRE(mi, RPMTAG_NAME, RPMMIRE_DEFAULT, '!gpg-pubkey');
00958 #endif
00959     while ((h = rpmdbNextIterator(mi)) != NULL) {
00960         rpmTagType type = RPM_NULL_TYPE;
00961         int_32 count = 0;
00962         int_32 * tidp;
00963 
00964         tidp = NULL;
00965         if (!hge(h, tag, &type, (void **)&tidp, &count) || tidp == NULL)
00966             continue;
00967 
00968         if (type == RPM_INT32_TYPE && (*tidp == 0 || *tidp == -1))
00969             continue;
00970 
00971         idtx = IDTXgrow(idtx, 1);
00972         if (idtx == NULL)
00973             continue;
00974         if (idtx->idt == NULL)
00975             continue;
00976 
00977         {   IDT idt;
00978             /*@-nullderef@*/
00979             idt = idtx->idt + idtx->nidt;
00980             /*@=nullderef@*/
00981             idt->h = headerLink(h);
00982             idt->key = NULL;
00983             idt->instance = rpmdbGetIteratorOffset(mi);
00984             idt->val.u32 = *tidp;
00985         }
00986         idtx->nidt++;
00987     }
00988     mi = rpmdbFreeIterator(mi);
00989     /*@=branchstate@*/
00990 
00991     return IDTXsort(idtx);
00992 }
00993 
00994 IDTX IDTXglob(rpmts ts, const char * globstr, rpmTag tag)
00995 {
00996     IDTX idtx = NULL;
00997     HGE_t hge = (HGE_t) headerGetEntry;
00998     Header h;
00999     int_32 * tidp;
01000     FD_t fd;
01001     const char ** av = NULL;
01002     int ac = 0;
01003     rpmRC rpmrc;
01004     int xx;
01005     int i;
01006 
01007     av = NULL;  ac = 0;
01008     xx = rpmGlob(globstr, &ac, &av);
01009 
01010     if (xx == 0)
01011     for (i = 0; i < ac; i++) {
01012         rpmTagType type;
01013         int_32 count;
01014         int isSource;
01015 
01016         fd = Fopen(av[i], "r.ufdio");
01017         if (fd == NULL || Ferror(fd)) {
01018             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), av[i],
01019                         Fstrerror(fd));
01020             if (fd != NULL) (void) Fclose(fd);
01021             continue;
01022         }
01023 
01024         rpmrc = rpmReadPackageFile(ts, fd, av[i], &h);
01025         (void) Fclose(fd);
01026         switch (rpmrc) {
01027         default:
01028             goto bottom;
01029             /*@notreached@*/ /*@switchbreak@*/ break;
01030         case RPMRC_NOTTRUSTED:
01031         case RPMRC_NOKEY:
01032         case RPMRC_OK:
01033             isSource = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
01034             if (isSource)
01035                 goto bottom;
01036             /*@switchbreak@*/ break;
01037         }
01038 
01039         tidp = NULL;
01040         /*@-branchstate@*/
01041         if (hge(h, tag, &type, (void **) &tidp, &count) && tidp != NULL) {
01042 
01043             idtx = IDTXgrow(idtx, 1);
01044             if (idtx == NULL || idtx->idt == NULL)
01045                 goto bottom;
01046 
01047             {   IDT idt;
01048                 idt = idtx->idt + idtx->nidt;
01049                 idt->h = headerLink(h);
01050                 idt->key = av[i];
01051                 av[i] = NULL;
01052                 idt->instance = 0;
01053                 idt->val.u32 = *tidp;
01054             }
01055             idtx->nidt++;
01056         }
01057         /*@=branchstate@*/
01058 bottom:
01059         h = headerFree(h);
01060     }
01061 
01062     for (i = 0; i < ac; i++)
01063         av[i] = _free(av[i]);
01064     av = _free(av);     ac = 0;
01065 
01066     return IDTXsort(idtx);
01067 }
01068 
01070 int rpmRollback(rpmts ts, struct rpmInstallArguments_s * ia, const char ** argv)
01071 {
01072     int ifmask= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE);
01073     unsigned thistid = 0xffffffff;
01074     unsigned prevtid;
01075     time_t tid;
01076     IDTX itids = NULL;
01077     IDTX rtids = NULL;
01078     IDT rp;
01079     int nrids = 0;
01080     IDT ip;
01081     int niids = 0;
01082     int rc = 0;
01083     int vsflags, ovsflags;
01084     int numAdded;
01085     int numRemoved;
01086     rpmps ps;
01087     int _unsafe_rollbacks = 0;
01088     rpmtransFlags transFlags = ia->transFlags;
01089 
01090     if (argv != NULL && *argv != NULL) {
01091         rc = -1;
01092         goto exit;
01093     }
01094 
01095     _unsafe_rollbacks = rpmExpandNumeric("%{?_unsafe_rollbacks}");
01096 
01097     vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
01098     if (ia->qva_flags & VERIFY_DIGEST)
01099         vsflags |= _RPMVSF_NODIGESTS;
01100     if (ia->qva_flags & VERIFY_SIGNATURE)
01101         vsflags |= _RPMVSF_NOSIGNATURES;
01102     if (ia->qva_flags & VERIFY_HDRCHK)
01103         vsflags |= RPMVSF_NOHDRCHK;
01104     vsflags |= RPMVSF_NEEDPAYLOAD;      /* XXX no legacy signatures */
01105     ovsflags = rpmtsSetVSFlags(ts, vsflags);
01106 
01107     (void) rpmtsSetFlags(ts, transFlags);
01108 
01109     itids = IDTXload(ts, RPMTAG_INSTALLTID);
01110     if (itids != NULL) {
01111         ip = itids->idt;
01112         niids = itids->nidt;
01113     } else {
01114         ip = NULL;
01115         niids = 0;
01116     }
01117 
01118     {   const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
01119         if (globstr == NULL || *globstr == '%') {
01120             globstr = _free(globstr);
01121             rc = -1;
01122             goto exit;
01123         }
01124         rtids = IDTXglob(ts, globstr, RPMTAG_REMOVETID);
01125 
01126         if (rtids != NULL) {
01127             rp = rtids->idt;
01128             nrids = rtids->nidt;
01129         } else {
01130             rp = NULL;
01131             nrids = 0;
01132         }
01133         globstr = _free(globstr);
01134     }
01135 
01136     {   int notifyFlags, xx;
01137         notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
01138         xx = rpmtsSetNotifyCallback(ts,
01139                         rpmShowProgress, (void *) ((long)notifyFlags));
01140     }
01141 
01142     /* Run transactions until rollback goal is achieved. */
01143     do {
01144         prevtid = thistid;
01145         rc = 0;
01146         rpmcliPackagesTotal = 0;
01147         numAdded = 0;
01148         numRemoved = 0;
01149         ia->installInterfaceFlags &= ~ifmask;
01150 
01151         /* Find larger of the remaining install/erase transaction id's. */
01152         thistid = 0;
01153         if (ip != NULL && ip->val.u32 > thistid)
01154             thistid = ip->val.u32;
01155         if (rp != NULL && rp->val.u32 > thistid)
01156             thistid = rp->val.u32;
01157 
01158         /* If we've achieved the rollback goal, then we're done. */
01159         if (thistid == 0 || thistid < ia->rbtid)
01160             break;
01161 
01162         /* If we've reached the (configured) rollback goal, then we're done. */
01163         if (_unsafe_rollbacks && thistid <= _unsafe_rollbacks)
01164             break;
01165 
01166         rpmtsEmpty(ts);
01167         (void) rpmtsSetFlags(ts, transFlags);
01168 
01169         /* Install the previously erased packages for this transaction. */
01170         while (rp != NULL && rp->val.u32 == thistid) {
01171 
01172             rpmMessage(RPMMESS_DEBUG, "\t+++ install %s\n",
01173                         (rp->key ? rp->key : "???"));
01174 
01175 /*@-abstract@*/
01176             rc = rpmtsAddInstallElement(ts, rp->h, (fnpyKey)rp->key,
01177                                0, ia->relocations);
01178 /*@=abstract@*/
01179             if (rc != 0)
01180                 goto exit;
01181 
01182             numAdded++;
01183             rpmcliPackagesTotal++;
01184             if (!(ia->installInterfaceFlags & ifmask))
01185                 ia->installInterfaceFlags |= INSTALL_UPGRADE;
01186 
01187 #ifdef  NOTYET
01188             rp->h = headerFree(rp->h);
01189 #endif
01190             nrids--;
01191             if (nrids > 0)
01192                 rp++;
01193             else
01194                 rp = NULL;
01195         }
01196 
01197         /* Erase the previously installed packages for this transaction. */
01198         while (ip != NULL && ip->val.u32 == thistid) {
01199 
01200             rpmMessage(RPMMESS_DEBUG,
01201                         "\t--- erase h#%u\n", ip->instance);
01202 
01203             rc = rpmtsAddEraseElement(ts, ip->h, ip->instance);
01204             if (rc != 0)
01205                 goto exit;
01206 
01207             numRemoved++;
01208 
01209             if (_unsafe_rollbacks)
01210                 rpmcliPackagesTotal++;
01211 
01212             if (!(ia->installInterfaceFlags & ifmask)) {
01213                 ia->installInterfaceFlags |= INSTALL_ERASE;
01214                 (void) rpmtsSetFlags(ts, (transFlags | RPMTRANS_FLAG_REVERSE));
01215             }
01216 
01217 #ifdef  NOTYET
01218             ip->instance = 0;
01219 #endif
01220             niids--;
01221             if (niids > 0)
01222                 ip++;
01223             else
01224                 ip = NULL;
01225         }
01226 
01227         /* Anything to do? */
01228         if (rpmcliPackagesTotal <= 0)
01229             break;
01230 
01231         tid = (time_t)thistid;
01232         rpmMessage(RPMMESS_NORMAL,
01233                 _("Rollback packages (+%d/-%d) to %-24.24s (0x%08x):\n"),
01234                         numAdded, numRemoved, ctime(&tid), tid);
01235 
01236         rc = rpmtsCheck(ts);
01237         ps = rpmtsProblems(ts);
01238         if (rc != 0 && rpmpsNumProblems(ps) > 0) {
01239             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
01240             rpmpsPrint(NULL, ps);
01241             ps = rpmpsFree(ps);
01242             goto exit;
01243         }
01244         ps = rpmpsFree(ps);
01245 
01246         rc = rpmtsOrder(ts);
01247         if (rc != 0)
01248             goto exit;
01249 
01250         /* Drop added/available package indices and dependency sets. */
01251         rpmtsClean(ts);
01252 
01253         rc = rpmtsRun(ts, NULL, (ia->probFilter|RPMPROB_FILTER_OLDPACKAGE));
01254         ps = rpmtsProblems(ts);
01255         if (rc > 0 && rpmpsNumProblems(ps) > 0)
01256             rpmpsPrint(stderr, ps);
01257         ps = rpmpsFree(ps);
01258         if (rc)
01259             goto exit;
01260 
01261         /* Clean up after successful rollback. */
01262         if (rtids && !rpmIsDebug()) {
01263             int i;
01264             if (rtids->idt)
01265             for (i = 0; i < rtids->nidt; i++) {
01266                 IDT rrp = rtids->idt + i;
01267                 if (rrp->val.u32 != thistid)
01268                     /*@innercontinue@*/ continue;
01269                 if (rrp->key)   /* XXX can't happen */
01270                     (void) unlink(rrp->key);
01271             }
01272         }
01273 
01274 
01275     } while (1);
01276 
01277 exit:
01278     rtids = IDTXfree(rtids);
01279     itids = IDTXfree(itids);
01280 
01281     rpmtsEmpty(ts);
01282     (void) rpmtsSetFlags(ts, transFlags);
01283 
01284     return rc;
01285 }

Generated on Fri Sep 30 15:11:36 2005 for rpm by doxygen 1.3.5