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

Generated on Thu Oct 25 09:23:14 2007 for rpm by  doxygen 1.5.1