lib/rpminstall.c

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

Generated on Wed Jan 28 12:45:24 2009 for rpm by  doxygen 1.4.7