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

rpminstall.c

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

Generated on Mon Mar 14 16:17:46 2005 for rpm by  doxygen 1.3.9.1