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

Generated on Tue Jan 5 15:36:37 2010 for rpm by  doxygen 1.4.7