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 (rpmtsSELinuxEnabled(ts) &&
00313         !(ia->transFlags & RPMTRANS_FLAG_NOCONTEXTS)) {
00314             const char *fn = rpmGetPath("%{?_install_file_context_path}", NULL);
00315             if (fn != NULL && *fn != '\0') {
00316                     matchpathcon_init(fn);
00317             }
00318     }
00319     (void) rpmtsSetFlags(ts, ia->transFlags);
00320 
00321     probFilter = ia->probFilter;
00322     relocations = ia->relocations;
00323 
00324     if (ia->installInterfaceFlags & INSTALL_UPGRADE)
00325         vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
00326     else
00327         vsflags = rpmExpandNumeric("%{?_vsflags_install}");
00328     if (ia->qva_flags & VERIFY_DIGEST)
00329         vsflags |= _RPMVSF_NODIGESTS;
00330     if (ia->qva_flags & VERIFY_SIGNATURE)
00331         vsflags |= _RPMVSF_NOSIGNATURES;
00332     if (ia->qva_flags & VERIFY_HDRCHK)
00333         vsflags |= RPMVSF_NOHDRCHK;
00334     ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
00335 
00336     {   int notifyFlags;
00337         notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
00338         xx = rpmtsSetNotifyCallback(ts,
00339                         rpmShowProgress, (void *) ((long)notifyFlags));
00340     }
00341 
00342     if ((eiu->relocations = relocations) != NULL) {
00343         while (eiu->relocations->oldPath)
00344             eiu->relocations++;
00345         if (eiu->relocations->newPath == NULL)
00346             eiu->relocations = NULL;
00347     }
00348 
00349     /* Build fully globbed list of arguments in argv[argc]. */
00350     /*@-branchstate@*/
00351     /*@-temptrans@*/
00352     for (eiu->fnp = fileArgv; *eiu->fnp != NULL; eiu->fnp++) {
00353     /*@=temptrans@*/
00354         av = _free(av); ac = 0;
00355         rc = rpmGlob(*eiu->fnp, &ac, &av);
00356         if (rc || ac == 0) {
00357             rpmError(RPMERR_OPEN, _("File not found by glob: %s\n"), *eiu->fnp);
00358             continue;
00359         }
00360 
00361         eiu->argv = xrealloc(eiu->argv, (eiu->argc+ac+1) * sizeof(*eiu->argv));
00362         memcpy(eiu->argv+eiu->argc, av, ac * sizeof(*av));
00363         eiu->argc += ac;
00364         eiu->argv[eiu->argc] = NULL;
00365     }
00366     /*@=branchstate@*/
00367     av = _free(av);     ac = 0;
00368 
00369 restart:
00370     /* Allocate sufficient storage for next set of args. */
00371     if (eiu->pkgx >= eiu->numPkgs) {
00372         eiu->numPkgs = eiu->pkgx + eiu->argc;
00373         eiu->pkgURL = xrealloc(eiu->pkgURL,
00374                         (eiu->numPkgs + 1) * sizeof(*eiu->pkgURL));
00375         memset(eiu->pkgURL + eiu->pkgx, 0,
00376                         ((eiu->argc + 1) * sizeof(*eiu->pkgURL)));
00377         eiu->pkgState = xrealloc(eiu->pkgState,
00378                         (eiu->numPkgs + 1) * sizeof(*eiu->pkgState));
00379         memset(eiu->pkgState + eiu->pkgx, 0,
00380                         ((eiu->argc + 1) * sizeof(*eiu->pkgState)));
00381     }
00382 
00383     /* Retrieve next set of args, cache on local storage. */
00384     for (i = 0; i < eiu->argc; i++) {
00385         fileURL = _free(fileURL);
00386         fileURL = eiu->argv[i];
00387         eiu->argv[i] = NULL;
00388 
00389 #ifdef  NOTYET
00390 if (fileURL[0] == '=') {
00391     rpmds this = rpmdsSingle(RPMTAG_REQUIRENAME, fileURL+1, NULL, 0);
00392 
00393     xx = rpmtsSolve(ts, this, NULL);
00394     if (ts->suggests && ts->nsuggests > 0) {
00395         fileURL = _free(fileURL);
00396         fileURL = ts->suggests[0];
00397         ts->suggests[0] = NULL;
00398         while (ts->nsuggests-- > 0) {
00399             if (ts->suggests[ts->nsuggests] == NULL)
00400                 continue;
00401             ts->suggests[ts->nsuggests] = _free(ts->suggests[ts->nsuggests]);
00402         }
00403         ts->suggests = _free(ts->suggests);
00404         rpmMessage(RPMMESS_DEBUG, _("Adding goal: %s\n"), fileURL);
00405         eiu->pkgURL[eiu->pkgx] = fileURL;
00406         fileURL = NULL;
00407         eiu->pkgx++;
00408     }
00409     this = rpmdsFree(this);
00410 } else
00411 #endif
00412 
00413         switch (urlIsURL(fileURL)) {
00414         case URL_IS_HTTPS:
00415         case URL_IS_HTTP:
00416         case URL_IS_FTP:
00417         {   const char *tfn;
00418 
00419             if (rpmIsVerbose())
00420                 fprintf(stdout, _("Retrieving %s\n"), fileURL);
00421 
00422             {   char tfnbuf[64];
00423                 const char * rootDir = rpmtsRootDir(ts);
00424                 if (!(rootDir && * rootDir))
00425                     rootDir = "";
00426                 strcpy(tfnbuf, "rpm-xfer.XXXXXX");
00427                 (void) mktemp(tfnbuf);
00428                 tfn = rpmGenPath(rootDir, "%{_tmppath}/", tfnbuf);
00429             }
00430 
00431             /* XXX undefined %{name}/%{version}/%{release} here */
00432             /* XXX %{_tmpdir} does not exist */
00433             rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn);
00434             rc = urlGetFile(fileURL, tfn);
00435             if (rc < 0) {
00436                 rpmMessage(RPMMESS_ERROR,
00437                         _("skipping %s - transfer failed - %s\n"),
00438                         fileURL, ftpStrerror(rc));
00439                 eiu->numFailed++;
00440                 eiu->pkgURL[eiu->pkgx] = NULL;
00441                 tfn = _free(tfn);
00442                 /*@switchbreak@*/ break;
00443             }
00444             eiu->pkgState[eiu->pkgx] = 1;
00445             eiu->pkgURL[eiu->pkgx] = tfn;
00446             eiu->pkgx++;
00447         }   /*@switchbreak@*/ break;
00448         case URL_IS_PATH:
00449         case URL_IS_DASH:       /* WRONG WRONG WRONG */
00450         case URL_IS_HKP:        /* WRONG WRONG WRONG */
00451         default:
00452             eiu->pkgURL[eiu->pkgx] = fileURL;
00453             fileURL = NULL;
00454             eiu->pkgx++;
00455             /*@switchbreak@*/ break;
00456         }
00457     }
00458     fileURL = _free(fileURL);
00459 
00460     if (eiu->numFailed) goto exit;
00461 
00462     /* Continue processing file arguments, building transaction set. */
00463     for (eiu->fnp = eiu->pkgURL+eiu->prevx;
00464          *eiu->fnp != NULL;
00465          eiu->fnp++, eiu->prevx++)
00466     {
00467         const char * fileName;
00468 
00469         rpmMessage(RPMMESS_DEBUG, "============== %s\n", *eiu->fnp);
00470         (void) urlPath(*eiu->fnp, &fileName);
00471 
00472         /* Try to read the header from a package file. */
00473         eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
00474         if (eiu->fd == NULL || Ferror(eiu->fd)) {
00475             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
00476                         Fstrerror(eiu->fd));
00477             if (eiu->fd != NULL) {
00478                 xx = Fclose(eiu->fd);
00479                 eiu->fd = NULL;
00480             }
00481             eiu->numFailed++; *eiu->fnp = NULL;
00482             continue;
00483         }
00484 
00485         /* Read the header, verifying signatures (if present). */
00486         tvsflags = rpmtsSetVSFlags(ts, vsflags);
00487         eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
00488         tvsflags = rpmtsSetVSFlags(ts, tvsflags);
00489         xx = Fclose(eiu->fd);
00490         eiu->fd = NULL;
00491 
00492         switch (eiu->rpmrc) {
00493         case RPMRC_FAIL:
00494             rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *eiu->fnp);
00495             eiu->numFailed++; *eiu->fnp = NULL;
00496             continue;
00497             /*@notreached@*/ /*@switchbreak@*/ break;
00498         case RPMRC_NOTFOUND:
00499             goto maybe_manifest;
00500             /*@notreached@*/ /*@switchbreak@*/ break;
00501         case RPMRC_NOTTRUSTED:
00502         case RPMRC_NOKEY:
00503         case RPMRC_OK:
00504         default:
00505             /*@switchbreak@*/ break;
00506         }
00507 
00508         eiu->isSource = headerIsEntry(eiu->h, RPMTAG_SOURCEPACKAGE);
00509 
00510         if (eiu->isSource) {
00511             rpmMessage(RPMMESS_DEBUG, _("\tadded source package [%d]\n"),
00512                 eiu->numSRPMS);
00513             eiu->sourceURL = xrealloc(eiu->sourceURL,
00514                                 (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL));
00515             eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp;
00516             *eiu->fnp = NULL;
00517             eiu->numSRPMS++;
00518             eiu->sourceURL[eiu->numSRPMS] = NULL;
00519             continue;
00520         }
00521 
00522         if (eiu->relocations) {
00523             const char ** paths;
00524             int pft;
00525             int c;
00526 
00527             if (headerGetEntry(eiu->h, RPMTAG_PREFIXES, &pft,
00528                                        (void **) &paths, &c) && (c == 1))
00529             {
00530                 eiu->relocations->oldPath = xstrdup(paths[0]);
00531                 paths = headerFreeData(paths, pft);
00532             } else {
00533                 const char * name;
00534                 xx = headerNVR(eiu->h, &name, NULL, NULL);
00535                 rpmMessage(RPMMESS_ERROR,
00536                                _("package %s is not relocatable\n"), name);
00537                 eiu->numFailed++;
00538                 goto exit;
00539                 /*@notreached@*/
00540             }
00541         }
00542 
00543         /* On --freshen, verify package is installed and newer */
00544         if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
00545             rpmdbMatchIterator mi;
00546             const char * name;
00547             Header oldH;
00548             int count;
00549 
00550             xx = headerNVR(eiu->h, &name, NULL, NULL);
00551             mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0);
00552             count = rpmdbGetIteratorCount(mi);
00553             while ((oldH = rpmdbNextIterator(mi)) != NULL) {
00554                 if (rpmVersionCompare(oldH, eiu->h) < 0)
00555                     /*@innercontinue@*/ continue;
00556                 /* same or newer package already installed */
00557                 count = 0;
00558                 /*@innerbreak@*/ break;
00559             }
00560             mi = rpmdbFreeIterator(mi);
00561             if (count == 0) {
00562                 eiu->h = headerFree(eiu->h);
00563                 continue;
00564             }
00565             /* Package is newer than those currently installed. */
00566         }
00567 
00568         /*@-abstract@*/
00569         rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName,
00570                         (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
00571                         relocations);
00572         /*@=abstract@*/
00573 
00574         /* XXX reference held by transaction set */
00575         eiu->h = headerFree(eiu->h);
00576         if (eiu->relocations)
00577             eiu->relocations->oldPath = _free(eiu->relocations->oldPath);
00578 
00579         switch(rc) {
00580         case 0:
00581             rpmMessage(RPMMESS_DEBUG, _("\tadded binary package [%d]\n"),
00582                         eiu->numRPMS);
00583             /*@switchbreak@*/ break;
00584         case 1:
00585             rpmMessage(RPMMESS_ERROR,
00586                             _("error reading from file %s\n"), *eiu->fnp);
00587             eiu->numFailed++;
00588             goto exit;
00589             /*@notreached@*/ /*@switchbreak@*/ break;
00590         case 2:
00591             rpmMessage(RPMMESS_ERROR,
00592                             _("file %s requires a newer version of RPM\n"),
00593                             *eiu->fnp);
00594             eiu->numFailed++;
00595             goto exit;
00596             /*@notreached@*/ /*@switchbreak@*/ break;
00597         default:
00598             eiu->numFailed++;
00599             goto exit;
00600             /*@notreached@*/ /*@switchbreak@*/ break;
00601         }
00602 
00603         eiu->numRPMS++;
00604         continue;
00605 
00606 maybe_manifest:
00607         /* Try to read a package manifest. */
00608         eiu->fd = Fopen(*eiu->fnp, "r.fpio");
00609         if (eiu->fd == NULL || Ferror(eiu->fd)) {
00610             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *eiu->fnp,
00611                         Fstrerror(eiu->fd));
00612             if (eiu->fd != NULL) {
00613                 xx = Fclose(eiu->fd);
00614                 eiu->fd = NULL;
00615             }
00616             eiu->numFailed++; *eiu->fnp = NULL;
00617             break;
00618         }
00619 
00620         /* Read list of packages from manifest. */
00621 /*@-nullstate@*/ /* FIX: *eiu->argv can be NULL */
00622         rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv);
00623 /*@=nullstate@*/
00624         if (rc != RPMRC_OK)
00625             rpmError(RPMERR_MANIFEST, _("%s: not an rpm package (or package manifest): %s\n"),
00626                         *eiu->fnp, Fstrerror(eiu->fd));
00627         xx = Fclose(eiu->fd);
00628         eiu->fd = NULL;
00629 
00630         /* If successful, restart the query loop. */
00631         if (rc == RPMRC_OK) {
00632             eiu->prevx++;
00633             goto restart;
00634         }
00635 
00636         eiu->numFailed++; *eiu->fnp = NULL;
00637         break;
00638     }
00639 
00640     rpmMessage(RPMMESS_DEBUG, _("found %d source and %d binary packages\n"),
00641                 eiu->numSRPMS, eiu->numRPMS);
00642 
00643     if (eiu->numFailed) goto exit;
00644 
00645     if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NODEPS)) {
00646 
00647         if (rpmtsCheck(ts)) {
00648             eiu->numFailed = eiu->numPkgs;
00649             stopInstall = 1;
00650         }
00651 
00652         ps = rpmtsProblems(ts);
00653         if (!stopInstall && rpmpsNumProblems(ps) > 0) {
00654             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
00655             rpmpsPrint(NULL, ps);
00656             eiu->numFailed = eiu->numPkgs;
00657             stopInstall = 1;
00658 
00659             /*@-branchstate@*/
00660             if (ts->suggests != NULL && ts->nsuggests > 0) {
00661                 rpmMessage(RPMMESS_NORMAL, _("    Suggested resolutions:\n"));
00662                 for (i = 0; i < ts->nsuggests; i++) {
00663                     const char * str = ts->suggests[i];
00664 
00665                     if (str == NULL)
00666                         break;
00667 
00668                     rpmMessage(RPMMESS_NORMAL, "\t%s\n", str);
00669                 
00670                     ts->suggests[i] = NULL;
00671                     str = _free(str);
00672                 }
00673                 ts->suggests = _free(ts->suggests);
00674             }
00675             /*@=branchstate@*/
00676         }
00677         ps = rpmpsFree(ps);
00678     }
00679 
00680     if (eiu->numRPMS && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
00681         if (rpmtsOrder(ts)) {
00682             eiu->numFailed = eiu->numPkgs;
00683             stopInstall = 1;
00684         }
00685     }
00686 
00687     if (eiu->numRPMS && !stopInstall) {
00688 
00689         rpmcliPackagesTotal += eiu->numSRPMS;
00690 
00691         rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n"));
00692 
00693         /* Drop added/available package indices and dependency sets. */
00694         rpmtsClean(ts);
00695 
00696         rc = rpmtsRun(ts, NULL, probFilter);
00697         ps = rpmtsProblems(ts);
00698 
00699         if (rc < 0) {
00700             eiu->numFailed += eiu->numRPMS;
00701         } else if (rc > 0) {
00702             eiu->numFailed += rc;
00703             if (rpmpsNumProblems(ps) > 0)
00704                 rpmpsPrint(stderr, ps);
00705         }
00706         ps = rpmpsFree(ps);
00707     }
00708 
00709     if (eiu->numSRPMS && !stopInstall) {
00710         if (eiu->sourceURL != NULL)
00711         for (i = 0; i < eiu->numSRPMS; i++) {
00712             if (eiu->sourceURL[i] == NULL) continue;
00713             eiu->fd = Fopen(eiu->sourceURL[i], "r.ufdio");
00714             if (eiu->fd == NULL || Ferror(eiu->fd)) {
00715                 rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"),
00716                            eiu->sourceURL[i], Fstrerror(eiu->fd));
00717                 if (eiu->fd != NULL) {
00718                     xx = Fclose(eiu->fd);
00719                     eiu->fd = NULL;
00720                 }
00721                 continue;
00722             }
00723 
00724             if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
00725                 eiu->rpmrc = rpmInstallSourcePackage(ts, eiu->fd, NULL, NULL);
00726                 if (eiu->rpmrc != RPMRC_OK) eiu->numFailed++;
00727             }
00728 
00729             xx = Fclose(eiu->fd);
00730             eiu->fd = NULL;
00731         }
00732     }
00733 
00734 exit:
00735     if (eiu->pkgURL != NULL)
00736     for (i = 0; i < eiu->numPkgs; i++) {
00737         if (eiu->pkgURL[i] == NULL) continue;
00738         if (eiu->pkgState[i] == 1)
00739             (void) Unlink(eiu->pkgURL[i]);
00740         eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
00741     }
00742     eiu->pkgState = _free(eiu->pkgState);
00743     eiu->pkgURL = _free(eiu->pkgURL);
00744     eiu->argv = _free(eiu->argv);
00745 
00746     rpmtsEmpty(ts);
00747 
00748     return eiu->numFailed;
00749 }
00750 /*@=bounds@*/
00751 
00752 int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia,
00753                 const char ** argv)
00754 {
00755     int count;
00756     const char ** arg;
00757     int numFailed = 0;
00758     int stopUninstall = 0;
00759     int numPackages = 0;
00760     rpmVSFlags vsflags, ovsflags;
00761     rpmps ps;
00762 
00763     if (argv == NULL) return 0;
00764 
00765     vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
00766     if (ia->qva_flags & VERIFY_DIGEST)
00767         vsflags |= _RPMVSF_NODIGESTS;
00768     if (ia->qva_flags & VERIFY_SIGNATURE)
00769         vsflags |= _RPMVSF_NOSIGNATURES;
00770     if (ia->qva_flags & VERIFY_HDRCHK)
00771         vsflags |= RPMVSF_NOHDRCHK;
00772     ovsflags = rpmtsSetVSFlags(ts, vsflags);
00773 
00774     if (rpmExpandNumeric("%{?_repackage_all_erasures}"))
00775         ia->transFlags |= RPMTRANS_FLAG_REPACKAGE;
00776 
00777     (void) rpmtsSetFlags(ts, ia->transFlags);
00778 
00779 #ifdef  NOTYET  /* XXX no callbacks on erase yet */
00780     {   int notifyFlags;
00781         notifyFlags = ia->eraseInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
00782         xx = rpmtsSetNotifyCallback(ts,
00783                         rpmShowProgress, (void *) ((long)notifyFlags)
00784     }
00785 #endif
00786 
00787     ts->goal = TSM_ERASE;
00788 
00789     for (arg = argv; *arg; arg++) {
00790         rpmdbMatchIterator mi;
00791 
00792         /* XXX HACK to get rpmdbFindByLabel out of the API */
00793         mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
00794         if (mi == NULL) {
00795             rpmMessage(RPMMESS_ERROR, _("package %s is not installed\n"), *arg);
00796             numFailed++;
00797         } else {
00798             Header h;   /* XXX iterator owns the reference */
00799             count = 0;
00800             while ((h = rpmdbNextIterator(mi)) != NULL) {
00801                 unsigned int recOffset = rpmdbGetIteratorOffset(mi);
00802 
00803                 if (!(count++ == 0 || (ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES))) {
00804                     rpmMessage(RPMMESS_ERROR, _("\"%s\" specifies multiple packages\n"),
00805                         *arg);
00806                     numFailed++;
00807                     /*@innerbreak@*/ break;
00808                 }
00809                 if (recOffset) {
00810                     (void) rpmtsAddEraseElement(ts, h, recOffset);
00811                     numPackages++;
00812                 }
00813             }
00814         }
00815         mi = rpmdbFreeIterator(mi);
00816     }
00817 
00818     if (numFailed) goto exit;
00819 
00820     if (!(ia->eraseInterfaceFlags & UNINSTALL_NODEPS)) {
00821 
00822         if (rpmtsCheck(ts)) {
00823             numFailed = numPackages;
00824             stopUninstall = 1;
00825         }
00826 
00827         ps = rpmtsProblems(ts);
00828         if (!stopUninstall && rpmpsNumProblems(ps) > 0) {
00829             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
00830             rpmpsPrint(NULL, ps);
00831             numFailed += numPackages;
00832             stopUninstall = 1;
00833         }
00834         ps = rpmpsFree(ps);
00835     }
00836 
00837     if (!stopUninstall && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
00838         if (rpmtsOrder(ts)) {
00839             numFailed += numPackages;
00840             stopUninstall = 1;
00841         }
00842     }
00843 
00844     if (numPackages && !stopUninstall) {
00845         (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_REVERSE));
00846 
00847         /* Drop added/available package indices and dependency sets. */
00848         rpmtsClean(ts);
00849 
00850         numPackages = rpmtsRun(ts, NULL, ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES));
00851         ps = rpmtsProblems(ts);
00852         if (rpmpsNumProblems(ps) > 0)
00853             rpmpsPrint(NULL, ps);
00854         numFailed += numPackages;
00855         stopUninstall = 1;
00856         ps = rpmpsFree(ps);
00857     }
00858 
00859 exit:
00860     rpmtsEmpty(ts);
00861 
00862     return numFailed;
00863 }
00864 
00865 int rpmInstallSource(rpmts ts, const char * arg,
00866                 const char ** specFilePtr, const char ** cookie)
00867 {
00868     FD_t fd;
00869     int rc;
00870 
00871 
00872     fd = Fopen(arg, "r.ufdio");
00873     if (fd == NULL || Ferror(fd)) {
00874         rpmMessage(RPMMESS_ERROR, _("cannot open %s: %s\n"), arg, Fstrerror(fd));
00875         if (fd != NULL) (void) Fclose(fd);
00876         return 1;
00877     }
00878 
00879     if (rpmIsVerbose())
00880         fprintf(stdout, _("Installing %s\n"), arg);
00881 
00882     {
00883         rpmVSFlags ovsflags =
00884                 rpmtsSetVSFlags(ts, (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD));
00885         rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie);
00886         rc = (rpmrc == RPMRC_OK ? 0 : 1);
00887         ovsflags = rpmtsSetVSFlags(ts, ovsflags);
00888     }
00889     if (rc != 0) {
00890         rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), arg);
00891         /*@-unqualifiedtrans@*/
00892         if (specFilePtr && *specFilePtr)
00893             *specFilePtr = _free(*specFilePtr);
00894         if (cookie && *cookie)
00895             *cookie = _free(*cookie);
00896         /*@=unqualifiedtrans@*/
00897     }
00898 
00899     (void) Fclose(fd);
00900 
00901     return rc;
00902 }
00903 
00904 /*@unchecked@*/
00905 static int reverse = -1;
00906 
00909 static int IDTintcmp(const void * a, const void * b)
00910         /*@*/
00911 {
00912     /*@-castexpose@*/
00913     return ( reverse * (((IDT)a)->val.u32 - ((IDT)b)->val.u32) );
00914     /*@=castexpose@*/
00915 }
00916 
00917 IDTX IDTXfree(IDTX idtx)
00918 {
00919     if (idtx) {
00920         int i;
00921         if (idtx->idt)
00922         for (i = 0; i < idtx->nidt; i++) {
00923             IDT idt = idtx->idt + i;
00924             idt->h = headerFree(idt->h);
00925             idt->key = _free(idt->key);
00926         }
00927         idtx->idt = _free(idtx->idt);
00928         idtx = _free(idtx);
00929     }
00930     return NULL;
00931 }
00932 
00933 IDTX IDTXnew(void)
00934 {
00935     IDTX idtx = xcalloc(1, sizeof(*idtx));
00936     idtx->delta = 10;
00937     idtx->size = sizeof(*((IDT)0));
00938     return idtx;
00939 }
00940 
00941 IDTX IDTXgrow(IDTX idtx, int need)
00942 {
00943     if (need < 0) return NULL;
00944     if (idtx == NULL)
00945         idtx = IDTXnew();
00946     if (need == 0) return idtx;
00947 
00948     if ((idtx->nidt + need) > idtx->alloced) {
00949         while (need > 0) {
00950             idtx->alloced += idtx->delta;
00951             need -= idtx->delta;
00952         }
00953         idtx->idt = xrealloc(idtx->idt, (idtx->alloced * idtx->size) );
00954     }
00955     return idtx;
00956 }
00957 
00958 IDTX IDTXsort(IDTX idtx)
00959 {
00960     if (idtx != NULL && idtx->idt != NULL && idtx->nidt > 0)
00961         qsort(idtx->idt, idtx->nidt, idtx->size, IDTintcmp);
00962     return idtx;
00963 }
00964 
00965 IDTX IDTXload(rpmts ts, rpmTag tag)
00966 {
00967     IDTX idtx = NULL;
00968     rpmdbMatchIterator mi;
00969     HGE_t hge = (HGE_t) headerGetEntry;
00970     Header h;
00971 
00972     /*@-branchstate@*/
00973     mi = rpmtsInitIterator(ts, tag, NULL, 0);
00974 #ifdef  NOTYET
00975     (void) rpmdbSetIteratorRE(mi, RPMTAG_NAME, RPMMIRE_DEFAULT, '!gpg-pubkey');
00976 #endif
00977     while ((h = rpmdbNextIterator(mi)) != NULL) {
00978         rpmTagType type = RPM_NULL_TYPE;
00979         int_32 count = 0;
00980         int_32 * tidp;
00981 
00982         tidp = NULL;
00983         if (!hge(h, tag, &type, (void **)&tidp, &count) || tidp == NULL)
00984             continue;
00985 
00986         if (type == RPM_INT32_TYPE && (*tidp == 0 || *tidp == -1))
00987             continue;
00988 
00989         idtx = IDTXgrow(idtx, 1);
00990         if (idtx == NULL)
00991             continue;
00992         if (idtx->idt == NULL)
00993             continue;
00994 
00995         {   IDT idt;
00996             /*@-nullderef@*/
00997             idt = idtx->idt + idtx->nidt;
00998             /*@=nullderef@*/
00999             idt->h = headerLink(h);
01000             idt->key = NULL;
01001             idt->instance = rpmdbGetIteratorOffset(mi);
01002             idt->val.u32 = *tidp;
01003         }
01004         idtx->nidt++;
01005     }
01006     mi = rpmdbFreeIterator(mi);
01007     /*@=branchstate@*/
01008 
01009     return IDTXsort(idtx);
01010 }
01011 
01012 IDTX IDTXglob(rpmts ts, const char * globstr, rpmTag tag)
01013 {
01014     IDTX idtx = NULL;
01015     HGE_t hge = (HGE_t) headerGetEntry;
01016     Header h;
01017     int_32 * tidp;
01018     FD_t fd;
01019     const char ** av = NULL;
01020     int ac = 0;
01021     rpmRC rpmrc;
01022     int xx;
01023     int i;
01024 
01025     av = NULL;  ac = 0;
01026     xx = rpmGlob(globstr, &ac, &av);
01027 
01028     if (xx == 0)
01029     for (i = 0; i < ac; i++) {
01030         rpmTagType type;
01031         int_32 count;
01032         int isSource;
01033 
01034         fd = Fopen(av[i], "r.ufdio");
01035         if (fd == NULL || Ferror(fd)) {
01036             rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), av[i],
01037                         Fstrerror(fd));
01038             if (fd != NULL) (void) Fclose(fd);
01039             continue;
01040         }
01041 
01042         rpmrc = rpmReadPackageFile(ts, fd, av[i], &h);
01043         (void) Fclose(fd);
01044         switch (rpmrc) {
01045         default:
01046             goto bottom;
01047             /*@notreached@*/ /*@switchbreak@*/ break;
01048         case RPMRC_NOTTRUSTED:
01049         case RPMRC_NOKEY:
01050         case RPMRC_OK:
01051             isSource = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
01052             if (isSource)
01053                 goto bottom;
01054             /*@switchbreak@*/ break;
01055         }
01056 
01057         tidp = NULL;
01058         /*@-branchstate@*/
01059         if (hge(h, tag, &type, (void **) &tidp, &count) && tidp != NULL) {
01060 
01061             idtx = IDTXgrow(idtx, 1);
01062             if (idtx == NULL || idtx->idt == NULL)
01063                 goto bottom;
01064 
01065             {   IDT idt;
01066                 idt = idtx->idt + idtx->nidt;
01067                 idt->h = headerLink(h);
01068                 idt->key = av[i];
01069                 av[i] = NULL;
01070                 idt->instance = 0;
01071                 idt->val.u32 = *tidp;
01072             }
01073             idtx->nidt++;
01074         }
01075         /*@=branchstate@*/
01076 bottom:
01077         h = headerFree(h);
01078     }
01079 
01080     for (i = 0; i < ac; i++)
01081         av[i] = _free(av[i]);
01082     av = _free(av);     ac = 0;
01083 
01084     return IDTXsort(idtx);
01085 }
01086 
01088 int rpmRollback(rpmts ts, struct rpmInstallArguments_s * ia, const char ** argv)
01089 {
01090     int ifmask= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE);
01091     unsigned thistid = 0xffffffff;
01092     unsigned prevtid;
01093     time_t tid;
01094     IDTX itids = NULL;
01095     IDTX rtids = NULL;
01096     IDT rp;
01097     int nrids = 0;
01098     IDT ip;
01099     int niids = 0;
01100     int rc = 0;
01101     int vsflags, ovsflags;
01102     int numAdded;
01103     int numRemoved;
01104     rpmps ps;
01105     int _unsafe_rollbacks = 0;
01106     rpmtransFlags transFlags = ia->transFlags;
01107 
01108     if (argv != NULL && *argv != NULL) {
01109         rc = -1;
01110         goto exit;
01111     }
01112 
01113     _unsafe_rollbacks = rpmExpandNumeric("%{?_unsafe_rollbacks}");
01114 
01115     vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
01116     if (ia->qva_flags & VERIFY_DIGEST)
01117         vsflags |= _RPMVSF_NODIGESTS;
01118     if (ia->qva_flags & VERIFY_SIGNATURE)
01119         vsflags |= _RPMVSF_NOSIGNATURES;
01120     if (ia->qva_flags & VERIFY_HDRCHK)
01121         vsflags |= RPMVSF_NOHDRCHK;
01122     vsflags |= RPMVSF_NEEDPAYLOAD;      /* XXX no legacy signatures */
01123     ovsflags = rpmtsSetVSFlags(ts, vsflags);
01124 
01125     (void) rpmtsSetFlags(ts, transFlags);
01126 
01127     /*  Make the transaction a rollback transaction.  In a rollback
01128      *  a best effort is what we want 
01129      */
01130     rpmtsSetType(ts, RPMTRANS_TYPE_ROLLBACK);
01131 
01132     itids = IDTXload(ts, RPMTAG_INSTALLTID);
01133     if (itids != NULL) {
01134         ip = itids->idt;
01135         niids = itids->nidt;
01136     } else {
01137         ip = NULL;
01138         niids = 0;
01139     }
01140 
01141     {   const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
01142         if (globstr == NULL || *globstr == '%') {
01143             globstr = _free(globstr);
01144             rc = -1;
01145             goto exit;
01146         }
01147         rtids = IDTXglob(ts, globstr, RPMTAG_REMOVETID);
01148 
01149         if (rtids != NULL) {
01150             rp = rtids->idt;
01151             nrids = rtids->nidt;
01152         } else {
01153             rp = NULL;
01154             nrids = 0;
01155         }
01156         globstr = _free(globstr);
01157     }
01158 
01159     {   int notifyFlags, xx;
01160         notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
01161         xx = rpmtsSetNotifyCallback(ts,
01162                         rpmShowProgress, (void *) ((long)notifyFlags));
01163     }
01164 
01165     /* Run transactions until rollback goal is achieved. */
01166     do {
01167         prevtid = thistid;
01168         rc = 0;
01169         rpmcliPackagesTotal = 0;
01170         numAdded = 0;
01171         numRemoved = 0;
01172         ia->installInterfaceFlags &= ~ifmask;
01173 
01174         /* Find larger of the remaining install/erase transaction id's. */
01175         thistid = 0;
01176         if (ip != NULL && ip->val.u32 > thistid)
01177             thistid = ip->val.u32;
01178         if (rp != NULL && rp->val.u32 > thistid)
01179             thistid = rp->val.u32;
01180 
01181         /* If we've achieved the rollback goal, then we're done. */
01182         if (thistid == 0 || thistid < ia->rbtid)
01183             break;
01184 
01185         /* If we've reached the (configured) rollback goal, then we're done. */
01186         if (_unsafe_rollbacks && thistid <= _unsafe_rollbacks)
01187             break;
01188 
01189         rpmtsEmpty(ts);
01190         (void) rpmtsSetFlags(ts, transFlags);
01191 
01192         /* Install the previously erased packages for this transaction. */
01193         while (rp != NULL && rp->val.u32 == thistid) {
01194 
01195             rpmMessage(RPMMESS_DEBUG, "\t+++ install %s\n",
01196                         (rp->key ? rp->key : "???"));
01197 
01198 /*@-abstract@*/
01199             rc = rpmtsAddInstallElement(ts, rp->h, (fnpyKey)rp->key,
01200                                0, ia->relocations);
01201 /*@=abstract@*/
01202             if (rc != 0)
01203                 goto exit;
01204 
01205             numAdded++;
01206             rpmcliPackagesTotal++;
01207             if (!(ia->installInterfaceFlags & ifmask))
01208                 ia->installInterfaceFlags |= INSTALL_UPGRADE;
01209 
01210 #ifdef  NOTYET
01211             rp->h = headerFree(rp->h);
01212 #endif
01213             nrids--;
01214             if (nrids > 0)
01215                 rp++;
01216             else
01217                 rp = NULL;
01218         }
01219 
01220         /* Erase the previously installed packages for this transaction. */
01221         while (ip != NULL && ip->val.u32 == thistid) {
01222 
01223             rpmMessage(RPMMESS_DEBUG,
01224                         "\t--- erase h#%u\n", ip->instance);
01225 
01226             rc = rpmtsAddEraseElement(ts, ip->h, ip->instance);
01227             if (rc != 0)
01228                 goto exit;
01229 
01230             numRemoved++;
01231 
01232             if (_unsafe_rollbacks)
01233                 rpmcliPackagesTotal++;
01234 
01235             if (!(ia->installInterfaceFlags & ifmask)) {
01236                 ia->installInterfaceFlags |= INSTALL_ERASE;
01237                 (void) rpmtsSetFlags(ts, (transFlags | RPMTRANS_FLAG_REVERSE));
01238             }
01239 
01240 #ifdef  NOTYET
01241             ip->instance = 0;
01242 #endif
01243             niids--;
01244             if (niids > 0)
01245                 ip++;
01246             else
01247                 ip = NULL;
01248         }
01249 
01250         /* Anything to do? */
01251         if (rpmcliPackagesTotal <= 0)
01252             break;
01253 
01254         tid = (time_t)thistid;
01255         rpmMessage(RPMMESS_NORMAL,
01256                 _("Rollback packages (+%d/-%d) to %-24.24s (0x%08x):\n"),
01257                         numAdded, numRemoved, ctime(&tid), tid);
01258 
01259         rc = rpmtsCheck(ts);
01260         ps = rpmtsProblems(ts);
01261         if (rc != 0 && rpmpsNumProblems(ps) > 0) {
01262             rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
01263             rpmpsPrint(NULL, ps);
01264             ps = rpmpsFree(ps);
01265             goto exit;
01266         }
01267         ps = rpmpsFree(ps);
01268 
01269         rc = rpmtsOrder(ts);
01270         if (rc != 0)
01271             goto exit;
01272 
01273         /* Drop added/available package indices and dependency sets. */
01274         rpmtsClean(ts);
01275 
01276         rc = rpmtsRun(ts, NULL, (ia->probFilter|RPMPROB_FILTER_OLDPACKAGE));
01277         ps = rpmtsProblems(ts);
01278         if (rc > 0 && rpmpsNumProblems(ps) > 0)
01279             rpmpsPrint(stderr, ps);
01280         ps = rpmpsFree(ps);
01281         if (rc)
01282             goto exit;
01283 
01284         /* Clean up after successful rollback. */
01285         if (rtids && !rpmIsDebug()) {
01286             int i;
01287             rpmMessage(RPMMESS_NORMAL, _("Cleaning up repackaged packages:\n"));
01288             if (rtids->idt)
01289             for (i = 0; i < rtids->nidt; i++) {
01290                 IDT rrp = rtids->idt + i;
01291                 if (rrp->val.u32 != thistid)
01292                     /*@innercontinue@*/ continue;
01293                 if (rrp->key) { /* XXX can't happen */
01294                     rpmMessage(RPMMESS_NORMAL, _("\tRemoving %s:\n"), rrp->key);
01295                     (void) unlink(rrp->key);    /* XXX: Should check rc??? */
01296                 }
01297             }
01298         }
01299 
01300 
01301     } while (1);
01302 
01303 exit:
01304     rtids = IDTXfree(rtids);
01305     itids = IDTXfree(itids);
01306 
01307     rpmtsEmpty(ts);
01308     (void) rpmtsSetFlags(ts, transFlags);
01309 
01310     return rc;
01311 }

Generated on Fri Oct 12 08:44:53 2007 for rpm by  doxygen 1.5.2