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

lib/transaction.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 #include <rpmlib.h>
00007 
00008 #include <rpmmacro.h>   /* XXX for rpmExpand */
00009 
00010 #include "fsm.h"
00011 #include "psm.h"
00012 
00013 #include "rpmdb.h"
00014 
00015 #include "rpmds.h"
00016 
00017 #define _RPMFI_INTERNAL
00018 #include "rpmfi.h"
00019 
00020 #define _RPMTE_INTERNAL
00021 #include "rpmte.h"
00022 
00023 #define _RPMTS_INTERNAL
00024 #include "rpmts.h"
00025 
00026 #include "cpio.h"
00027 #include "fprint.h"
00028 #include "legacy.h"     /* XXX domd5 */
00029 #include "misc.h" /* XXX stripTrailingChar, splitString, currentDirectory */
00030 
00031 #include "debug.h"
00032 
00033 /*@access Header @*/            /* XXX ts->notify arg1 is void ptr */
00034 /*@access rpmps @*/     /* XXX need rpmProblemSetOK() */
00035 /*@access dbiIndexSet @*/
00036 
00037 /*@access rpmpsm @*/
00038 
00039 /*@access alKey @*/
00040 /*@access fnpyKey @*/
00041 
00042 /*@access rpmfi @*/
00043 
00044 /*@access rpmte @*/
00045 /*@access rpmtsi @*/
00046 /*@access rpmts @*/
00047 
00050 static int archOkay(/*@null@*/ const char * pkgArch)
00051         /*@*/
00052 {
00053     if (pkgArch == NULL) return 0;
00054     return (rpmMachineScore(RPM_MACHTABLE_INSTARCH, pkgArch) ? 1 : 0);
00055 }
00056 
00059 static int osOkay(/*@null@*/ const char * pkgOs)
00060         /*@*/
00061 {
00062     if (pkgOs == NULL) return 0;
00063     return (rpmMachineScore(RPM_MACHTABLE_INSTOS, pkgOs) ? 1 : 0);
00064 }
00065 
00068 static int sharedCmp(const void * one, const void * two)
00069         /*@*/
00070 {
00071     sharedFileInfo a = (sharedFileInfo) one;
00072     sharedFileInfo b = (sharedFileInfo) two;
00073 
00074     if (a->otherPkg < b->otherPkg)
00075         return -1;
00076     else if (a->otherPkg > b->otherPkg)
00077         return 1;
00078 
00079     return 0;
00080 }
00081 
00090 /* XXX only ts->{probs,rpmdb} modified */
00091 /*@-bounds@*/
00092 static int handleInstInstalledFiles(const rpmts ts,
00093                 rpmte p, rpmfi fi,
00094                 sharedFileInfo shared,
00095                 int sharedCount, int reportConflicts)
00096         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00097         /*@modifies ts, fi, rpmGlobalMacroContext, fileSystem, internalState @*/
00098 {
00099     uint_32 tscolor = rpmtsColor(ts);
00100     uint_32 otecolor, tecolor;
00101     uint_32 oFColor, FColor;
00102     const char * altNEVR = NULL;
00103     rpmfi otherFi = NULL;
00104     int numReplaced = 0;
00105     rpmps ps;
00106     int i;
00107 
00108     {   rpmdbMatchIterator mi;
00109         Header h;
00110         int scareMem = 0;
00111 
00112         mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
00113                         &shared->otherPkg, sizeof(shared->otherPkg));
00114         while ((h = rpmdbNextIterator(mi)) != NULL) {
00115             altNEVR = hGetNEVR(h, NULL);
00116             otherFi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
00117             break;
00118         }
00119         mi = rpmdbFreeIterator(mi);
00120     }
00121 
00122     /* Compute package color. */
00123     tecolor = rpmteColor(p);
00124     tecolor &= tscolor;
00125 
00126     /* Compute other pkg color. */
00127     otecolor = 0;
00128     otherFi = rpmfiInit(otherFi, 0);
00129     if (otherFi != NULL)
00130     while (rpmfiNext(otherFi) >= 0)
00131         otecolor |= rpmfiFColor(otherFi);
00132     otecolor &= tscolor;
00133 
00134     if (otherFi == NULL)
00135         return 1;
00136 
00137     fi->replaced = xcalloc(sharedCount, sizeof(*fi->replaced));
00138 
00139     ps = rpmtsProblems(ts);
00140     for (i = 0; i < sharedCount; i++, shared++) {
00141         int otherFileNum, fileNum;
00142         int isCfgFile;
00143 
00144         otherFileNum = shared->otherFileNum;
00145         (void) rpmfiSetFX(otherFi, otherFileNum);
00146         oFColor = rpmfiFColor(otherFi);
00147         oFColor &= tscolor;
00148 
00149         fileNum = shared->pkgFileNum;
00150         (void) rpmfiSetFX(fi, fileNum);
00151         FColor = rpmfiFColor(fi);
00152         FColor &= tscolor;
00153 
00154         isCfgFile = ((rpmfiFFlags(otherFi) | rpmfiFFlags(fi)) & RPMFILE_CONFIG);
00155 
00156 #ifdef  DYING
00157         /* XXX another tedious segfault, assume file state normal. */
00158         if (otherStates && otherStates[otherFileNum] != RPMFILE_STATE_NORMAL)
00159             continue;
00160 #endif
00161 
00162         if (XFA_SKIPPING(fi->actions[fileNum]))
00163             continue;
00164 
00165         if (rpmfiCompare(otherFi, fi)) {
00166             int rConflicts;
00167 
00168             rConflicts = reportConflicts;
00169             /* Resolve file conflicts to prefer Elf64 (if not forced). */
00170             if (tscolor != 0 && FColor != 0 && FColor != oFColor)
00171             {
00172                 if (oFColor & 0x2) {
00173                     fi->actions[fileNum] = FA_SKIP;
00174                     rConflicts = 0;
00175                 } else
00176                 if (FColor & 0x2) {
00177                     fi->actions[fileNum] = FA_CREATE;
00178                     rConflicts = 0;
00179                 }
00180             }
00181 
00182             if (rConflicts) {
00183                 rpmpsAppend(ps, RPMPROB_FILE_CONFLICT,
00184                         rpmteNEVR(p), rpmteKey(p),
00185                         rpmfiDN(fi), rpmfiBN(fi),
00186                         altNEVR,
00187                         0);
00188             }
00189             /* Save file identifier to mark as state REPLACED. */
00190             if ( !(isCfgFile || XFA_SKIPPING(fi->actions[fileNum])) ) {
00191                 /*@-assignexpose@*/ /* FIX: p->replaced, not fi */
00192                 if (!shared->isRemoved)
00193                     fi->replaced[numReplaced++] = *shared;
00194                 /*@=assignexpose@*/
00195             }
00196         }
00197 
00198         /* Determine config file dispostion, skipping missing files (if any). */
00199         if (isCfgFile) {
00200             int skipMissing =
00201                 ((rpmtsFlags(ts) & RPMTRANS_FLAG_ALLFILES) ? 0 : 1);
00202             fileAction action = rpmfiDecideFate(otherFi, fi, skipMissing);
00203             fi->actions[fileNum] = action;
00204         }
00205         fi->replacedSizes[fileNum] = rpmfiFSize(otherFi);
00206     }
00207     ps = rpmpsFree(ps);
00208 
00209     altNEVR = _free(altNEVR);
00210     otherFi = rpmfiFree(otherFi);
00211 
00212     fi->replaced = xrealloc(fi->replaced,       /* XXX memory leak */
00213                            sizeof(*fi->replaced) * (numReplaced + 1));
00214     fi->replaced[numReplaced].otherPkg = 0;
00215 
00216     return 0;
00217 }
00218 /*@=bounds@*/
00219 
00222 /* XXX only ts->rpmdb modified */
00223 static int handleRmvdInstalledFiles(const rpmts ts, rpmfi fi,
00224                 sharedFileInfo shared, int sharedCount)
00225         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00226         /*@modifies ts, fi, rpmGlobalMacroContext, fileSystem, internalState @*/
00227 {
00228     HGE_t hge = fi->hge;
00229     Header h;
00230     const char * otherStates;
00231     int i, xx;
00232    
00233     rpmdbMatchIterator mi;
00234 
00235     mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
00236                         &shared->otherPkg, sizeof(shared->otherPkg));
00237     h = rpmdbNextIterator(mi);
00238     if (h == NULL) {
00239         mi = rpmdbFreeIterator(mi);
00240         return 1;
00241     }
00242 
00243     xx = hge(h, RPMTAG_FILESTATES, NULL, (void **) &otherStates, NULL);
00244 
00245 /*@-boundswrite@*/
00246     for (i = 0; i < sharedCount; i++, shared++) {
00247         int otherFileNum, fileNum;
00248         otherFileNum = shared->otherFileNum;
00249         fileNum = shared->pkgFileNum;
00250 
00251         if (otherStates[otherFileNum] != RPMFILE_STATE_NORMAL)
00252             continue;
00253 
00254         fi->actions[fileNum] = FA_SKIP;
00255     }
00256 /*@=boundswrite@*/
00257 
00258     mi = rpmdbFreeIterator(mi);
00259 
00260     return 0;
00261 }
00262 
00263 #define ISROOT(_d)      (((_d)[0] == '/' && (_d)[1] == '\0') ? "" : (_d))
00264 
00265 /*@unchecked@*/
00266 int _fps_debug = 0;
00267 
00268 static int fpsCompare (const void * one, const void * two)
00269         /*@*/
00270 {
00271     const struct fingerPrint_s * a = (const struct fingerPrint_s *)one;
00272     const struct fingerPrint_s * b = (const struct fingerPrint_s *)two;
00273     int adnlen = strlen(a->entry->dirName);
00274     int asnlen = (a->subDir ? strlen(a->subDir) : 0);
00275     int abnlen = strlen(a->baseName);
00276     int bdnlen = strlen(b->entry->dirName);
00277     int bsnlen = (b->subDir ? strlen(b->subDir) : 0);
00278     int bbnlen = strlen(b->baseName);
00279     char * afn, * bfn, * t;
00280     int rc = 0;
00281 
00282     if (adnlen == 1 && asnlen != 0) adnlen = 0;
00283     if (bdnlen == 1 && bsnlen != 0) bdnlen = 0;
00284 
00285 /*@-boundswrite@*/
00286     afn = t = alloca(adnlen+asnlen+abnlen+2);
00287     if (adnlen) t = stpcpy(t, a->entry->dirName);
00288     *t++ = '/';
00289     if (a->subDir && asnlen) t = stpcpy(t, a->subDir);
00290     if (abnlen) t = stpcpy(t, a->baseName);
00291     if (afn[0] == '/' && afn[1] == '/') afn++;
00292 
00293     bfn = t = alloca(bdnlen+bsnlen+bbnlen+2);
00294     if (bdnlen) t = stpcpy(t, b->entry->dirName);
00295     *t++ = '/';
00296     if (b->subDir && bsnlen) t = stpcpy(t, b->subDir);
00297     if (bbnlen) t = stpcpy(t, b->baseName);
00298     if (bfn[0] == '/' && bfn[1] == '/') bfn++;
00299 /*@=boundswrite@*/
00300 
00301     rc = strcmp(afn, bfn);
00302 /*@-modfilesys@*/
00303 if (_fps_debug)
00304 fprintf(stderr, "\trc(%d) = strcmp(\"%s\", \"%s\")\n", rc, afn, bfn);
00305 /*@=modfilesys@*/
00306 
00307 /*@-modfilesys@*/
00308 if (_fps_debug)
00309 fprintf(stderr, "\t%s/%s%s\trc %d\n",
00310 ISROOT(b->entry->dirName),
00311 (b->subDir ? b->subDir : ""),
00312 b->baseName,
00313 rc
00314 );
00315 /*@=modfilesys@*/
00316 
00317     return rc;
00318 }
00319 
00320 /*@unchecked@*/
00321 static int _linear_fps_search = 0;
00322 
00323 static int findFps(const struct fingerPrint_s * fiFps,
00324                 const struct fingerPrint_s * otherFps,
00325                 int otherFc)
00326         /*@*/
00327 {
00328     int otherFileNum;
00329 
00330 /*@-modfilesys@*/
00331 if (_fps_debug)
00332 fprintf(stderr, "==> %s/%s%s\n",
00333 ISROOT(fiFps->entry->dirName),
00334 (fiFps->subDir ? fiFps->subDir : ""),
00335 fiFps->baseName);
00336 /*@=modfilesys@*/
00337 
00338   if (_linear_fps_search) {
00339 
00340 linear:
00341     for (otherFileNum = 0; otherFileNum < otherFc; otherFileNum++, otherFps++) {
00342 
00343 /*@-modfilesys@*/
00344 if (_fps_debug)
00345 fprintf(stderr, "\t%4d %s/%s%s\n", otherFileNum,
00346 ISROOT(otherFps->entry->dirName),
00347 (otherFps->subDir ? otherFps->subDir : ""),
00348 otherFps->baseName);
00349 /*@=modfilesys@*/
00350 
00351         /* If the addresses are the same, so are the values. */
00352         if (fiFps == otherFps)
00353             break;
00354 
00355         /* Otherwise, compare fingerprints by value. */
00356         /*@-nullpass@*/ /* LCL: looks good to me */
00357         if (FP_EQUAL((*fiFps), (*otherFps)))
00358             break;
00359         /*@=nullpass@*/
00360     }
00361 
00362 if (otherFileNum == otherFc) {
00363 /*@-modfilesys@*/
00364 if (_fps_debug)
00365 fprintf(stderr, "*** FP_EQUAL NULL %s/%s%s\n",
00366 ISROOT(fiFps->entry->dirName),
00367 (fiFps->subDir ? fiFps->subDir : ""),
00368 fiFps->baseName);
00369 /*@=modfilesys@*/
00370 }
00371 
00372     return otherFileNum;
00373 
00374   } else {
00375 
00376     const struct fingerPrint_s * bingoFps;
00377 
00378 /*@-boundswrite@*/
00379     bingoFps = bsearch(fiFps, otherFps, otherFc, sizeof(*otherFps), fpsCompare);
00380 /*@=boundswrite@*/
00381     if (bingoFps == NULL) {
00382 /*@-modfilesys@*/
00383 if (_fps_debug)
00384 fprintf(stderr, "*** bingoFps NULL %s/%s%s\n",
00385 ISROOT(fiFps->entry->dirName),
00386 (fiFps->subDir ? fiFps->subDir : ""),
00387 fiFps->baseName);
00388 /*@=modfilesys@*/
00389         goto linear;
00390     }
00391 
00392     /* If the addresses are the same, so are the values. */
00393     /*@-nullpass@*/     /* LCL: looks good to me */
00394     if (!(fiFps == bingoFps || FP_EQUAL((*fiFps), (*bingoFps)))) {
00395 /*@-modfilesys@*/
00396 if (_fps_debug)
00397 fprintf(stderr, "***  BAD %s/%s%s\n",
00398 ISROOT(bingoFps->entry->dirName),
00399 (bingoFps->subDir ? bingoFps->subDir : ""),
00400 bingoFps->baseName);
00401 /*@=modfilesys@*/
00402         goto linear;
00403     }
00404 
00405     otherFileNum = (bingoFps != NULL ? (bingoFps - otherFps) : 0);
00406 
00407   }
00408 
00409     return otherFileNum;
00410 }
00411 
00415 /* XXX only ts->{probs,di} modified */
00416 static void handleOverlappedFiles(const rpmts ts,
00417                 const rpmte p, rpmfi fi)
00418         /*@globals h_errno, fileSystem, internalState @*/
00419         /*@modifies ts, fi, fileSystem, internalState @*/
00420 {
00421     uint_32 fixupSize = 0;
00422     rpmps ps;
00423     const char * fn;
00424     int i, j;
00425   
00426     ps = rpmtsProblems(ts);
00427     fi = rpmfiInit(fi, 0);
00428     if (fi != NULL)
00429     while ((i = rpmfiNext(fi)) >= 0) {
00430         uint_32 tscolor = rpmtsColor(ts);
00431         uint_32 oFColor, FColor;
00432         struct fingerPrint_s * fiFps;
00433         int otherPkgNum, otherFileNum;
00434         rpmfi otherFi;
00435         int_32 FFlags;
00436         int_16 FMode;
00437         const rpmfi * recs;
00438         int numRecs;
00439 
00440         if (XFA_SKIPPING(fi->actions[i]))
00441             continue;
00442 
00443         fn = rpmfiFN(fi);
00444         fiFps = fi->fps + i;
00445         FFlags = rpmfiFFlags(fi);
00446         FMode = rpmfiFMode(fi);
00447         FColor = rpmfiFColor(fi);
00448         FColor &= tscolor;
00449 
00450         fixupSize = 0;
00451 
00452         /*
00453          * Retrieve all records that apply to this file. Note that the
00454          * file info records were built in the same order as the packages
00455          * will be installed and removed so the records for an overlapped
00456          * files will be sorted in exactly the same order.
00457          */
00458         (void) htGetEntry(ts->ht, fiFps,
00459                         (const void ***) &recs, &numRecs, NULL);
00460 
00461         /*
00462          * If this package is being added, look only at other packages
00463          * being added -- removed packages dance to a different tune.
00464          *
00465          * If both this and the other package are being added, overlapped
00466          * files must be identical (or marked as a conflict). The
00467          * disposition of already installed config files leads to
00468          * a small amount of extra complexity.
00469          *
00470          * If this package is being removed, then there are two cases that
00471          * need to be worried about:
00472          * If the other package is being added, then skip any overlapped files
00473          * so that this package removal doesn't nuke the overlapped files
00474          * that were just installed.
00475          * If both this and the other package are being removed, then each
00476          * file removal from preceding packages needs to be skipped so that
00477          * the file removal occurs only on the last occurence of an overlapped
00478          * file in the transaction set.
00479          *
00480          */
00481 
00482         /* Locate this overlapped file in the set of added/removed packages. */
00483         for (j = 0; j < numRecs && recs[j] != fi; j++)
00484             {};
00485 
00486         /* Find what the previous disposition of this file was. */
00487         otherFileNum = -1;                      /* keep gcc quiet */
00488         otherFi = NULL;
00489         for (otherPkgNum = j - 1; otherPkgNum >= 0; otherPkgNum--) {
00490             struct fingerPrint_s * otherFps;
00491             int otherFc;
00492 
00493             otherFi = recs[otherPkgNum];
00494 
00495             /* Added packages need only look at other added packages. */
00496             if (rpmteType(p) == TR_ADDED && rpmteType(otherFi->te) != TR_ADDED)
00497                 /*@innercontinue@*/ continue;
00498 
00499             otherFps = otherFi->fps;
00500             otherFc = rpmfiFC(otherFi);
00501 
00502             otherFileNum = findFps(fiFps, otherFps, otherFc);
00503             (void) rpmfiSetFX(otherFi, otherFileNum);
00504 
00505             /* XXX Happens iff fingerprint for incomplete package install. */
00506             if (otherFi->actions[otherFileNum] != FA_UNKNOWN)
00507                 /*@innerbreak@*/ break;
00508         }
00509 
00510         oFColor = rpmfiFColor(otherFi);
00511         oFColor &= tscolor;
00512 
00513 /*@-boundswrite@*/
00514         switch (rpmteType(p)) {
00515         case TR_ADDED:
00516           { struct stat sb;
00517             int reportConflicts =
00518                 !(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACENEWFILES);
00519             int done = 0;
00520 
00521             if (otherPkgNum < 0) {
00522                 /* XXX is this test still necessary? */
00523                 if (fi->actions[i] != FA_UNKNOWN)
00524                     /*@switchbreak@*/ break;
00525                 if ((FFlags & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
00526                     /* Here is a non-overlapped pre-existing config file. */
00527                     fi->actions[i] = (FFlags & RPMFILE_NOREPLACE)
00528                         ? FA_ALTNAME : FA_BACKUP;
00529                 } else {
00530                     fi->actions[i] = FA_CREATE;
00531                 }
00532                 /*@switchbreak@*/ break;
00533             }
00534 
00535 assert(otherFi != NULL);
00536             /* Mark added overlapped non-identical files as a conflict. */
00537             if (rpmfiCompare(otherFi, fi)) {
00538                 int rConflicts;
00539 
00540                 rConflicts = reportConflicts;
00541                 /* Resolve file conflicts to prefer Elf64 (if not forced) ... */
00542                 if (tscolor != 0) {
00543                     if (FColor & 0x2) {
00544                         /* ... last Elf64 file is installed ... */
00545                         if (!XFA_SKIPPING(fi->actions[i])) {
00546                             /* XXX static helpers are order dependent. Ick. */
00547                             if (strcmp(fn, "/usr/sbin/libgcc_post_upgrade")
00548                              && strcmp(fn, "/usr/sbin/glibc_post_upgrade"))
00549                                 otherFi->actions[otherFileNum] = FA_SKIP;
00550                         }
00551                         fi->actions[i] = FA_CREATE;
00552                         rConflicts = 0;
00553                     } else
00554                     if (oFColor & 0x2) {
00555                         /* ... first Elf64 file is installed ... */
00556                         if (XFA_SKIPPING(fi->actions[i]))
00557                             otherFi->actions[otherFileNum] = FA_CREATE;
00558                         fi->actions[i] = FA_SKIP;
00559                         rConflicts = 0;
00560                     } else
00561                     if (FColor == 0 && oFColor == 0) {
00562                         /* ... otherwise, do both, last in wins. */
00563                         otherFi->actions[otherFileNum] = FA_CREATE;
00564                         fi->actions[i] = FA_CREATE;
00565                         rConflicts = 0;
00566                     }
00567                     done = 1;
00568                 }
00569 
00570                 if (rConflicts) {
00571                     rpmpsAppend(ps, RPMPROB_NEW_FILE_CONFLICT,
00572                         rpmteNEVR(p), rpmteKey(p),
00573                         fn, NULL,
00574                         rpmteNEVR(otherFi->te),
00575                         0);
00576                 }
00577             }
00578 
00579             /* Try to get the disk accounting correct even if a conflict. */
00580             fixupSize = rpmfiFSize(otherFi);
00581 
00582             if ((FFlags & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
00583                 /* Here is an overlapped  pre-existing config file. */
00584                 fi->actions[i] = (FFlags & RPMFILE_NOREPLACE)
00585                         ? FA_ALTNAME : FA_SKIP;
00586             } else {
00587                 if (!done)
00588                     fi->actions[i] = FA_CREATE;
00589             }
00590           } /*@switchbreak@*/ break;
00591 
00592         case TR_REMOVED:
00593             if (otherPkgNum >= 0) {
00594 assert(otherFi != NULL);
00595                 /* Here is an overlapped added file we don't want to nuke. */
00596                 if (otherFi->actions[otherFileNum] != FA_ERASE) {
00597                     /* On updates, don't remove files. */
00598                     fi->actions[i] = FA_SKIP;
00599                     /*@switchbreak@*/ break;
00600                 }
00601                 /* Here is an overlapped removed file: skip in previous. */
00602                 otherFi->actions[otherFileNum] = FA_SKIP;
00603             }
00604             if (XFA_SKIPPING(fi->actions[i]))
00605                 /*@switchbreak@*/ break;
00606             if (rpmfiFState(fi) != RPMFILE_STATE_NORMAL)
00607                 /*@switchbreak@*/ break;
00608             if (!(S_ISREG(FMode) && (FFlags & RPMFILE_CONFIG))) {
00609                 fi->actions[i] = FA_ERASE;
00610                 /*@switchbreak@*/ break;
00611             }
00612                 
00613             /* Here is a pre-existing modified config file that needs saving. */
00614             {   char md5sum[50];
00615                 const unsigned char * MD5 = rpmfiMD5(fi);
00616                 if (!domd5(fn, md5sum, 0, NULL) && memcmp(MD5, md5sum, 16)) {
00617                     fi->actions[i] = FA_BACKUP;
00618                     /*@switchbreak@*/ break;
00619                 }
00620             }
00621             fi->actions[i] = FA_ERASE;
00622             /*@switchbreak@*/ break;
00623         }
00624 /*@=boundswrite@*/
00625 
00626         /* Update disk space info for a file. */
00627         rpmtsUpdateDSI(ts, fiFps->entry->dev, rpmfiFSize(fi),
00628                 fi->replacedSizes[i], fixupSize, fi->actions[i]);
00629 
00630     }
00631     ps = rpmpsFree(ps);
00632 }
00633 
00641 static int ensureOlder(rpmts ts,
00642                 const rpmte p, const Header h)
00643         /*@modifies ts @*/
00644 {
00645     int_32 reqFlags = (RPMSENSE_LESS | RPMSENSE_EQUAL);
00646     const char * reqEVR;
00647     rpmds req;
00648     char * t;
00649     int nb;
00650     int rc;
00651 
00652     if (p == NULL || h == NULL)
00653         return 1;
00654 
00655 /*@-boundswrite@*/
00656     nb = strlen(rpmteNEVR(p)) + (rpmteE(p) != NULL ? strlen(rpmteE(p)) : 0) + 1;
00657     t = alloca(nb);
00658     *t = '\0';
00659     reqEVR = t;
00660     if (rpmteE(p) != NULL)      t = stpcpy( stpcpy(t, rpmteE(p)), ":");
00661     if (rpmteV(p) != NULL)      t = stpcpy(t, rpmteV(p));
00662     *t++ = '-';
00663     if (rpmteR(p) != NULL)      t = stpcpy(t, rpmteR(p));
00664 /*@=boundswrite@*/
00665     
00666     req = rpmdsSingle(RPMTAG_REQUIRENAME, rpmteN(p), reqEVR, reqFlags);
00667     rc = rpmdsNVRMatchesDep(h, req, _rpmds_nopromote);
00668     req = rpmdsFree(req);
00669 
00670     if (rc == 0) {
00671         rpmps ps = rpmtsProblems(ts);
00672         const char * altNEVR = hGetNEVR(h, NULL);
00673         rpmpsAppend(ps, RPMPROB_OLDPACKAGE,
00674                 rpmteNEVR(p), rpmteKey(p),
00675                 NULL, NULL,
00676                 altNEVR,
00677                 0);
00678         altNEVR = _free(altNEVR);
00679         ps = rpmpsFree(ps);
00680         rc = 1;
00681     } else
00682         rc = 0;
00683 
00684     return rc;
00685 }
00686 
00692 /*@-mustmod@*/ /* FIX: fi->actions is modified. */
00693 /*@-bounds@*/
00694 static void skipFiles(const rpmts ts, rpmfi fi)
00695         /*@globals rpmGlobalMacroContext, h_errno @*/
00696         /*@modifies fi, rpmGlobalMacroContext @*/
00697 {
00698     uint_32 tscolor = rpmtsColor(ts);
00699     uint_32 FColor;
00700     int noConfigs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONFIGS);
00701     int noDocs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NODOCS);
00702     char ** netsharedPaths = NULL;
00703     const char ** languages;
00704     const char * dn, * bn;
00705     int dnlen, bnlen, ix;
00706     const char * s;
00707     int * drc;
00708     char * dff;
00709     int dc;
00710     int i, j;
00711 
00712     if (!noDocs)
00713         noDocs = rpmExpandNumeric("%{_excludedocs}");
00714 
00715     {   const char *tmpPath = rpmExpand("%{_netsharedpath}", NULL);
00716         /*@-branchstate@*/
00717         if (tmpPath && *tmpPath != '%')
00718             netsharedPaths = splitString(tmpPath, strlen(tmpPath), ':');
00719         /*@=branchstate@*/
00720         tmpPath = _free(tmpPath);
00721     }
00722 
00723     s = rpmExpand("%{_install_langs}", NULL);
00724     /*@-branchstate@*/
00725     if (!(s && *s != '%'))
00726         s = _free(s);
00727     if (s) {
00728         languages = (const char **) splitString(s, strlen(s), ':');
00729         s = _free(s);
00730     } else
00731         languages = NULL;
00732     /*@=branchstate@*/
00733 
00734     /* Compute directory refcount, skip directory if now empty. */
00735     dc = rpmfiDC(fi);
00736     drc = alloca(dc * sizeof(*drc));
00737     memset(drc, 0, dc * sizeof(*drc));
00738     dff = alloca(dc * sizeof(*dff));
00739     memset(dff, 0, dc * sizeof(*dff));
00740 
00741     fi = rpmfiInit(fi, 0);
00742     if (fi != NULL)     /* XXX lclint */
00743     while ((i = rpmfiNext(fi)) >= 0)
00744     {
00745         char ** nsp;
00746 
00747         bn = rpmfiBN(fi);
00748         bnlen = strlen(bn);
00749         ix = rpmfiDX(fi);
00750         dn = rpmfiDN(fi);
00751         dnlen = strlen(dn);
00752         if (dn == NULL)
00753             continue;   /* XXX can't happen */
00754 
00755         drc[ix]++;
00756 
00757         /* Don't bother with skipped files */
00758         if (XFA_SKIPPING(fi->actions[i])) {
00759             drc[ix]--; dff[ix] = 1;
00760             continue;
00761         }
00762 
00763         /* Ignore colored files not in our rainbow. */
00764         FColor = rpmfiFColor(fi);
00765         if (tscolor && FColor && !(tscolor & FColor)) {
00766             drc[ix]--;  dff[ix] = 1;
00767             fi->actions[i] = FA_SKIPCOLOR;
00768             continue;
00769         }
00770 
00771         /*
00772          * Skip net shared paths.
00773          * Net shared paths are not relative to the current root (though
00774          * they do need to take package relocations into account).
00775          */
00776         for (nsp = netsharedPaths; nsp && *nsp; nsp++) {
00777             int len;
00778 
00779             len = strlen(*nsp);
00780             if (dnlen >= len) {
00781                 if (strncmp(dn, *nsp, len))
00782                     /*@innercontinue@*/ continue;
00783                 /* Only directories or complete file paths can be net shared */
00784                 if (!(dn[len] == '/' || dn[len] == '\0'))
00785                     /*@innercontinue@*/ continue;
00786             } else {
00787                 if (len < (dnlen + bnlen))
00788                     /*@innercontinue@*/ continue;
00789                 if (strncmp(dn, *nsp, dnlen))
00790                     /*@innercontinue@*/ continue;
00791                 if (strncmp(bn, (*nsp) + dnlen, bnlen))
00792                     /*@innercontinue@*/ continue;
00793                 len = dnlen + bnlen;
00794                 /* Only directories or complete file paths can be net shared */
00795                 if (!((*nsp)[len] == '/' || (*nsp)[len] == '\0'))
00796                     /*@innercontinue@*/ continue;
00797             }
00798 
00799             /*@innerbreak@*/ break;
00800         }
00801 
00802         if (nsp && *nsp) {
00803             drc[ix]--;  dff[ix] = 1;
00804             fi->actions[i] = FA_SKIPNETSHARED;
00805             continue;
00806         }
00807 
00808         /*
00809          * Skip i18n language specific files.
00810          */
00811         if (languages != NULL && fi->flangs != NULL && *fi->flangs[i]) {
00812             const char **lang, *l, *le;
00813             for (lang = languages; *lang != NULL; lang++) {
00814                 if (!strcmp(*lang, "all"))
00815                     /*@innerbreak@*/ break;
00816                 for (l = fi->flangs[i]; *l != '\0'; l = le) {
00817                     for (le = l; *le != '\0' && *le != '|'; le++)
00818                         {};
00819                     if ((le-l) > 0 && !strncmp(*lang, l, (le-l)))
00820                         /*@innerbreak@*/ break;
00821                     if (*le == '|') le++;       /* skip over | */
00822                 }
00823                 if (*l != '\0')
00824                     /*@innerbreak@*/ break;
00825             }
00826             if (*lang == NULL) {
00827                 drc[ix]--;      dff[ix] = 1;
00828                 fi->actions[i] = FA_SKIPNSTATE;
00829                 continue;
00830             }
00831         }
00832 
00833         /*
00834          * Skip config files if requested.
00835          */
00836         if (noConfigs && (rpmfiFFlags(fi) & RPMFILE_CONFIG)) {
00837             drc[ix]--;  dff[ix] = 1;
00838             fi->actions[i] = FA_SKIPNSTATE;
00839             continue;
00840         }
00841 
00842         /*
00843          * Skip documentation if requested.
00844          */
00845         if (noDocs && (rpmfiFFlags(fi) & RPMFILE_DOC)) {
00846             drc[ix]--;  dff[ix] = 1;
00847             fi->actions[i] = FA_SKIPNSTATE;
00848             continue;
00849         }
00850     }
00851 
00852     /* Skip (now empty) directories that had skipped files. */
00853 #ifndef NOTYET
00854     if (fi != NULL)     /* XXX can't happen */
00855     for (j = 0; j < dc; j++)
00856 #else
00857     if ((fi = rpmfiInitD(fi)) != NULL)
00858     while (j = rpmfiNextD(fi) >= 0)
00859 #endif
00860     {
00861 
00862         if (drc[j]) continue;   /* dir still has files. */
00863         if (!dff[j]) continue;  /* dir was not emptied here. */
00864         
00865         /* Find parent directory and basename. */
00866         dn = fi->dnl[j];        dnlen = strlen(dn) - 1;
00867         bn = dn + dnlen;        bnlen = 0;
00868         while (bn > dn && bn[-1] != '/') {
00869                 bnlen++;
00870                 dnlen--;
00871                 bn--;
00872         }
00873 
00874         /* If explicitly included in the package, skip the directory. */
00875         fi = rpmfiInit(fi, 0);
00876         if (fi != NULL)         /* XXX lclint */
00877         while ((i = rpmfiNext(fi)) >= 0) {
00878             const char * fdn, * fbn;
00879             int_16 fFMode;
00880 
00881             if (XFA_SKIPPING(fi->actions[i]))
00882                 /*@innercontinue@*/ continue;
00883 
00884             fFMode = rpmfiFMode(fi);
00885 
00886             if (whatis(fFMode) != XDIR)
00887                 /*@innercontinue@*/ continue;
00888             fdn = rpmfiDN(fi);
00889             if (strlen(fdn) != dnlen)
00890                 /*@innercontinue@*/ continue;
00891             if (strncmp(fdn, dn, dnlen))
00892                 /*@innercontinue@*/ continue;
00893             fbn = rpmfiBN(fi);
00894             if (strlen(fbn) != bnlen)
00895                 /*@innercontinue@*/ continue;
00896             if (strncmp(fbn, bn, bnlen))
00897                 /*@innercontinue@*/ continue;
00898             rpmMessage(RPMMESS_DEBUG, _("excluding directory %s\n"), dn);
00899             fi->actions[i] = FA_SKIPNSTATE;
00900             /*@innerbreak@*/ break;
00901         }
00902     }
00903 
00904 /*@-dependenttrans@*/
00905     if (netsharedPaths) freeSplitString(netsharedPaths);
00906 #ifdef  DYING   /* XXX freeFi will deal with this later. */
00907     fi->flangs = _free(fi->flangs);
00908 #endif
00909     if (languages) freeSplitString((char **)languages);
00910 /*@=dependenttrans@*/
00911 }
00912 /*@=bounds@*/
00913 /*@=mustmod@*/
00914 
00921 static /*@null@*/
00922 rpmfi rpmtsiFi(const rpmtsi tsi)
00923         /*@*/
00924 {
00925     rpmfi fi = NULL;
00926 
00927     if (tsi != NULL && tsi->ocsave != -1) {
00928         /*@-type -abstract@*/ /* FIX: rpmte not opaque */
00929         rpmte te = rpmtsElement(tsi->ts, tsi->ocsave);
00930         /*@-assignexpose@*/
00931         if (te != NULL && (fi = te->fi) != NULL)
00932             fi->te = te;
00933         /*@=assignexpose@*/
00934         /*@=type =abstract@*/
00935     }
00936     /*@-compdef -refcounttrans -usereleased @*/
00937     return fi;
00938     /*@=compdef =refcounttrans =usereleased @*/
00939 }
00940 
00941 #define NOTIFY(_ts, _al) /*@i@*/ if ((_ts)->notify) (void) (_ts)->notify _al
00942 
00943 int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
00944 {
00945     uint_32 tscolor = rpmtsColor(ts);
00946     int i, j;
00947     int ourrc = 0;
00948     int totalFileCount = 0;
00949     rpmfi fi;
00950     sharedFileInfo shared, sharedList;
00951     int numShared;
00952     int nexti;
00953     alKey lastFailKey;
00954     fingerPrintCache fpc;
00955     rpmps ps;
00956     rpmpsm psm;
00957     rpmtsi pi;  rpmte p;
00958     rpmtsi qi;  rpmte q;
00959     int numAdded;
00960     int numRemoved;
00961     int xx;
00962 
00963     /* XXX programmer error segfault avoidance. */
00964     if (rpmtsNElements(ts) <= 0)
00965         return -1;
00966 
00967     if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS)
00968         (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
00969     if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERS)
00970         (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransTriggers));
00971 
00972     if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB)
00973         (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
00974 
00975     ts->probs = rpmpsFree(ts->probs);
00976     ts->probs = rpmpsCreate();
00977 
00978     /* XXX Make sure the database is open RDWR for package install/erase. */
00979     {   int dbmode = (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
00980                 ? O_RDONLY : (O_RDWR|O_CREAT);
00981 
00982         /* Open database RDWR for installing packages. */
00983         if (rpmtsOpenDB(ts, dbmode))
00984             return -1;  /* XXX W2DO? */
00985     }
00986 
00987     ts->ignoreSet = ignoreSet;
00988     {   const char * currDir = currentDirectory();
00989         rpmtsSetCurrDir(ts, currDir);
00990         currDir = _free(currDir);
00991     }
00992 
00993     (void) rpmtsSetChrootDone(ts, 0);
00994 
00995     {   int_32 tid = (int_32) time(NULL);
00996         (void) rpmtsSetTid(ts, tid);
00997     }
00998 
00999     /* Get available space on mounted file systems. */
01000     xx = rpmtsInitDSI(ts);
01001 
01002     /* ===============================================
01003      * For packages being installed:
01004      * - verify package arch/os.
01005      * - verify package epoch:version-release is newer.
01006      * - count files.
01007      * For packages being removed:
01008      * - count files.
01009      */
01010 
01011 rpmMessage(RPMMESS_DEBUG, _("sanity checking %d elements\n"), rpmtsNElements(ts));
01012     ps = rpmtsProblems(ts);
01013     /* The ordering doesn't matter here */
01014     pi = rpmtsiInit(ts);
01015     while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) {
01016         rpmdbMatchIterator mi;
01017         int fc;
01018 
01019         if ((fi = rpmtsiFi(pi)) == NULL)
01020             continue;   /* XXX can't happen */
01021         fc = rpmfiFC(fi);
01022 
01023         if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREARCH) && !tscolor)
01024             if (!archOkay(rpmteA(p)))
01025                 rpmpsAppend(ps, RPMPROB_BADARCH,
01026                         rpmteNEVR(p), rpmteKey(p),
01027                         rpmteA(p), NULL,
01028                         NULL, 0);
01029 
01030         if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREOS))
01031             if (!osOkay(rpmteO(p)))
01032                 rpmpsAppend(ps, RPMPROB_BADOS,
01033                         rpmteNEVR(p), rpmteKey(p),
01034                         rpmteO(p), NULL,
01035                         NULL, 0);
01036 
01037         if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_OLDPACKAGE)) {
01038             Header h;
01039             mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0);
01040             while ((h = rpmdbNextIterator(mi)) != NULL)
01041                 xx = ensureOlder(ts, p, h);
01042             mi = rpmdbFreeIterator(mi);
01043         }
01044 
01045         if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEPKG)) {
01046             mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0);
01047             xx = rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_DEFAULT,
01048                                 rpmteE(p));
01049             xx = rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_DEFAULT,
01050                                 rpmteV(p));
01051             xx = rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_DEFAULT,
01052                                 rpmteR(p));
01053             if (tscolor) {
01054                 xx = rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_DEFAULT,
01055                                 rpmteA(p));
01056                 xx = rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_DEFAULT,
01057                                 rpmteO(p));
01058             }
01059 
01060             while (rpmdbNextIterator(mi) != NULL) {
01061                 rpmpsAppend(ps, RPMPROB_PKG_INSTALLED,
01062                         rpmteNEVR(p), rpmteKey(p),
01063                         NULL, NULL,
01064                         NULL, 0);
01065                 /*@innerbreak@*/ break;
01066             }
01067             mi = rpmdbFreeIterator(mi);
01068         }
01069 
01070         /* Count no. of files (if any). */
01071         totalFileCount += fc;
01072 
01073     }
01074     pi = rpmtsiFree(pi);
01075     ps = rpmpsFree(ps);
01076 
01077     /* The ordering doesn't matter here */
01078     pi = rpmtsiInit(ts);
01079     while ((p = rpmtsiNext(pi, TR_REMOVED)) != NULL) {
01080         int fc;
01081 
01082         if ((fi = rpmtsiFi(pi)) == NULL)
01083             continue;   /* XXX can't happen */
01084         fc = rpmfiFC(fi);
01085 
01086         totalFileCount += fc;
01087     }
01088     pi = rpmtsiFree(pi);
01089 
01090     /* ===============================================
01091      * Initialize transaction element file info for package:
01092      */
01093 
01094     /*
01095      * FIXME?: we'd be better off assembling one very large file list and
01096      * calling fpLookupList only once. I'm not sure that the speedup is
01097      * worth the trouble though.
01098      */
01099 rpmMessage(RPMMESS_DEBUG, _("computing %d file fingerprints\n"), totalFileCount);
01100 
01101     numAdded = numRemoved = 0;
01102     pi = rpmtsiInit(ts);
01103     while ((p = rpmtsiNext(pi, 0)) != NULL) {
01104         int fc;
01105 
01106         if ((fi = rpmtsiFi(pi)) == NULL)
01107             continue;   /* XXX can't happen */
01108         fc = rpmfiFC(fi);
01109 
01110         /*@-branchstate@*/
01111         switch (rpmteType(p)) {
01112         case TR_ADDED:
01113             numAdded++;
01114             fi->record = 0;
01115             /* Skip netshared paths, not our i18n files, and excluded docs */
01116             if (fc > 0)
01117                 skipFiles(ts, fi);
01118             /*@switchbreak@*/ break;
01119         case TR_REMOVED:
01120             numRemoved++;
01121             fi->record = rpmteDBOffset(p);
01122             /*@switchbreak@*/ break;
01123         }
01124         /*@=branchstate@*/
01125 
01126         fi->fps = (fc > 0 ? xmalloc(fc * sizeof(*fi->fps)) : NULL);
01127     }
01128     pi = rpmtsiFree(pi);
01129 
01130     if (!rpmtsChrootDone(ts)) {
01131         const char * rootDir = rpmtsRootDir(ts);
01132         xx = chdir("/");
01133         /*@-superuser -noeffect @*/
01134         if (rootDir != NULL)
01135             xx = chroot(rootDir);
01136         /*@=superuser =noeffect @*/
01137         (void) rpmtsSetChrootDone(ts, 1);
01138     }
01139 
01140     ts->ht = htCreate(totalFileCount * 2, 0, 0, fpHashFunction, fpEqual);
01141     fpc = fpCacheCreate(totalFileCount);
01142 
01143     /* ===============================================
01144      * Add fingerprint for each file not skipped.
01145      */
01146     pi = rpmtsiInit(ts);
01147     while ((p = rpmtsiNext(pi, 0)) != NULL) {
01148         int fc;
01149 
01150         (void) rpmdbCheckSignals();
01151 
01152         if ((fi = rpmtsiFi(pi)) == NULL)
01153             continue;   /* XXX can't happen */
01154         fc = rpmfiFC(fi);
01155 
01156         (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
01157         fpLookupList(fpc, fi->dnl, fi->bnl, fi->dil, fc, fi->fps);
01158         /*@-branchstate@*/
01159         fi = rpmfiInit(fi, 0);
01160         if (fi != NULL)         /* XXX lclint */
01161         while ((i = rpmfiNext(fi)) >= 0) {
01162             if (XFA_SKIPPING(fi->actions[i]))
01163                 /*@innercontinue@*/ continue;
01164             /*@-dependenttrans@*/
01165             htAddEntry(ts->ht, fi->fps + i, (void *) fi);
01166             /*@=dependenttrans@*/
01167         }
01168         /*@=branchstate@*/
01169         (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), fc);
01170 
01171     }
01172     pi = rpmtsiFree(pi);
01173 
01174     NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_START, 6, ts->orderCount,
01175         NULL, ts->notifyData));
01176 
01177     /* ===============================================
01178      * Compute file disposition for each package in transaction set.
01179      */
01180 rpmMessage(RPMMESS_DEBUG, _("computing file dispositions\n"));
01181     ps = rpmtsProblems(ts);
01182     pi = rpmtsiInit(ts);
01183     while ((p = rpmtsiNext(pi, 0)) != NULL) {
01184         dbiIndexSet * matches;
01185         int knownBad;
01186         int fc;
01187 
01188         (void) rpmdbCheckSignals();
01189 
01190         if ((fi = rpmtsiFi(pi)) == NULL)
01191             continue;   /* XXX can't happen */
01192         fc = rpmfiFC(fi);
01193 
01194         NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_PROGRESS, rpmtsiOc(pi),
01195                         ts->orderCount, NULL, ts->notifyData));
01196 
01197         if (fc == 0) continue;
01198 
01199         (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
01200         /* Extract file info for all files in this package from the database. */
01201         matches = xcalloc(fc, sizeof(*matches));
01202         if (rpmdbFindFpList(rpmtsGetRdb(ts), fi->fps, matches, fc)) {
01203             ps = rpmpsFree(ps);
01204             return 1;   /* XXX WTFO? */
01205         }
01206 
01207         numShared = 0;
01208         fi = rpmfiInit(fi, 0);
01209         while ((i = rpmfiNext(fi)) >= 0)
01210             numShared += dbiIndexSetCount(matches[i]);
01211 
01212         /* Build sorted file info list for this package. */
01213         shared = sharedList = xcalloc((numShared + 1), sizeof(*sharedList));
01214 
01215         fi = rpmfiInit(fi, 0);
01216         while ((i = rpmfiNext(fi)) >= 0) {
01217             /*
01218              * Take care not to mark files as replaced in packages that will
01219              * have been removed before we will get here.
01220              */
01221             for (j = 0; j < dbiIndexSetCount(matches[i]); j++) {
01222                 int ro;
01223                 ro = dbiIndexRecordOffset(matches[i], j);
01224                 knownBad = 0;
01225                 qi = rpmtsiInit(ts);
01226                 while ((q = rpmtsiNext(qi, TR_REMOVED)) != NULL) {
01227                     if (ro == knownBad)
01228                         /*@innerbreak@*/ break;
01229                     if (rpmteDBOffset(q) == ro)
01230                         knownBad = ro;
01231                 }
01232                 qi = rpmtsiFree(qi);
01233 
01234                 shared->pkgFileNum = i;
01235                 shared->otherPkg = dbiIndexRecordOffset(matches[i], j);
01236                 shared->otherFileNum = dbiIndexRecordFileNumber(matches[i], j);
01237                 shared->isRemoved = (knownBad == ro);
01238                 shared++;
01239             }
01240             matches[i] = dbiFreeIndexSet(matches[i]);
01241         }
01242         numShared = shared - sharedList;
01243         shared->otherPkg = -1;
01244         matches = _free(matches);
01245 
01246         /* Sort file info by other package index (otherPkg) */
01247         qsort(sharedList, numShared, sizeof(*shared), sharedCmp);
01248 
01249         /* For all files from this package that are in the database ... */
01250         /*@-branchstate@*/
01251         for (i = 0; i < numShared; i = nexti) {
01252             int beingRemoved;
01253 
01254             shared = sharedList + i;
01255 
01256             /* Find the end of the files in the other package. */
01257             for (nexti = i + 1; nexti < numShared; nexti++) {
01258                 if (sharedList[nexti].otherPkg != shared->otherPkg)
01259                     /*@innerbreak@*/ break;
01260             }
01261 
01262             /* Is this file from a package being removed? */
01263             beingRemoved = 0;
01264             if (ts->removedPackages != NULL)
01265             for (j = 0; j < ts->numRemovedPackages; j++) {
01266                 if (ts->removedPackages[j] != shared->otherPkg)
01267                     /*@innercontinue@*/ continue;
01268                 beingRemoved = 1;
01269                 /*@innerbreak@*/ break;
01270             }
01271 
01272             /* Determine the fate of each file. */
01273             switch (rpmteType(p)) {
01274             case TR_ADDED:
01275                 xx = handleInstInstalledFiles(ts, p, fi, shared, nexti - i,
01276         !(beingRemoved || (rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEOLDFILES)));
01277                 /*@switchbreak@*/ break;
01278             case TR_REMOVED:
01279                 if (!beingRemoved)
01280                     xx = handleRmvdInstalledFiles(ts, fi, shared, nexti - i);
01281                 /*@switchbreak@*/ break;
01282             }
01283         }
01284         /*@=branchstate@*/
01285 
01286         free(sharedList);
01287 
01288         /* Update disk space needs on each partition for this package. */
01289         handleOverlappedFiles(ts, p, fi);
01290 
01291         /* Check added package has sufficient space on each partition used. */
01292         switch (rpmteType(p)) {
01293         case TR_ADDED:
01294             rpmtsCheckDSIProblems(ts, p);
01295             /*@switchbreak@*/ break;
01296         case TR_REMOVED:
01297             /*@switchbreak@*/ break;
01298         }
01299         (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), fc);
01300     }
01301     pi = rpmtsiFree(pi);
01302     ps = rpmpsFree(ps);
01303 
01304     if (rpmtsChrootDone(ts)) {
01305         const char * currDir = rpmtsCurrDir(ts);
01306         /*@-superuser -noeffect @*/
01307         xx = chroot(".");
01308         /*@=superuser =noeffect @*/
01309         (void) rpmtsSetChrootDone(ts, 0);
01310         if (currDir != NULL)
01311             xx = chdir(currDir);
01312     }
01313 
01314     NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_STOP, 6, ts->orderCount,
01315         NULL, ts->notifyData));
01316 
01317     /* ===============================================
01318      * Free unused memory as soon as possible.
01319      */
01320     pi = rpmtsiInit(ts);
01321     while ((p = rpmtsiNext(pi, 0)) != NULL) {
01322         if ((fi = rpmtsiFi(pi)) == NULL)
01323             continue;   /* XXX can't happen */
01324         if (rpmfiFC(fi) == 0)
01325             continue;
01326         fi->fps = _free(fi->fps);
01327     }
01328     pi = rpmtsiFree(pi);
01329 
01330     fpc = fpCacheFree(fpc);
01331     ts->ht = htFree(ts->ht);
01332 
01333     /* ===============================================
01334      * If unfiltered problems exist, free memory and return.
01335      */
01336     if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS)
01337      || (ts->probs->numProblems &&
01338                 (okProbs != NULL || rpmpsTrim(ts->probs, okProbs)))
01339        )
01340     {
01341         return ts->orderCount;
01342     }
01343 
01344     /* ===============================================
01345      * Save removed files before erasing.
01346      */
01347     if (rpmtsFlags(ts) & (RPMTRANS_FLAG_DIRSTASH | RPMTRANS_FLAG_REPACKAGE)) {
01348         int progress;
01349 
01350         progress = 0;
01351         pi = rpmtsiInit(ts);
01352         while ((p = rpmtsiNext(pi, 0)) != NULL) {
01353 
01354             (void) rpmdbCheckSignals();
01355 
01356             if ((fi = rpmtsiFi(pi)) == NULL)
01357                 continue;       /* XXX can't happen */
01358             switch (rpmteType(p)) {
01359             case TR_ADDED:
01360                 /*@switchbreak@*/ break;
01361             case TR_REMOVED:
01362                 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_REPACKAGE))
01363                     /*@switchbreak@*/ break;
01364                 if (!progress)
01365                     NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_START,
01366                                 7, numRemoved, NULL, ts->notifyData));
01367 
01368                 NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_PROGRESS, progress,
01369                         numRemoved, NULL, ts->notifyData));
01370                 progress++;
01371 
01372                 (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_REPACKAGE), 0);
01373 
01374         /* XXX TR_REMOVED needs CPIO_MAP_{ABSOLUTE,ADDDOT} CPIO_ALL_HARDLINKS */
01375                 fi->mapflags |= CPIO_MAP_ABSOLUTE;
01376                 fi->mapflags |= CPIO_MAP_ADDDOT;
01377                 fi->mapflags |= CPIO_ALL_HARDLINKS;
01378                 psm = rpmpsmNew(ts, p, fi);
01379                 xx = rpmpsmStage(psm, PSM_PKGSAVE);
01380                 psm = rpmpsmFree(psm);
01381                 fi->mapflags &= ~CPIO_MAP_ABSOLUTE;
01382                 fi->mapflags &= ~CPIO_MAP_ADDDOT;
01383                 fi->mapflags &= ~CPIO_ALL_HARDLINKS;
01384 
01385                 (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_REPACKAGE), 0);
01386 
01387                 /*@switchbreak@*/ break;
01388             }
01389         }
01390         pi = rpmtsiFree(pi);
01391         if (progress) {
01392             NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_STOP, 7, numRemoved,
01393                         NULL, ts->notifyData));
01394         }
01395     }
01396 
01397     /* ===============================================
01398      * Install and remove packages.
01399      */
01400     lastFailKey = (alKey)-2;    /* erased packages have -1 */
01401     pi = rpmtsiInit(ts);
01402     /*@-branchstate@*/ /* FIX: fi reload needs work */
01403     while ((p = rpmtsiNext(pi, 0)) != NULL) {
01404         alKey pkgKey;
01405         int gotfd;
01406 
01407         (void) rpmdbCheckSignals();
01408 
01409         gotfd = 0;
01410         if ((fi = rpmtsiFi(pi)) == NULL)
01411             continue;   /* XXX can't happen */
01412         
01413         psm = rpmpsmNew(ts, p, fi);
01414 assert(psm != NULL);
01415         psm->unorderedSuccessor =
01416                 (rpmtsiOc(pi) >= rpmtsUnorderedSuccessors(ts, -1) ? 1 : 0);
01417 
01418         switch (rpmteType(p)) {
01419         case TR_ADDED:
01420             (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_INSTALL), 0);
01421 
01422             pkgKey = rpmteAddedKey(p);
01423 
01424             rpmMessage(RPMMESS_DEBUG, "========== +++ %s %s-%s 0x%x\n",
01425                 rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p));
01426 
01427             p->h = NULL;
01428             /*@-type@*/ /* FIX: rpmte not opaque */
01429             {
01430                 /*@-noeffectuncon@*/ /* FIX: notify annotations */
01431                 p->fd = ts->notify(p->h, RPMCALLBACK_INST_OPEN_FILE, 0, 0,
01432                                 rpmteKey(p), ts->notifyData);
01433                 /*@=noeffectuncon@*/
01434                 if (rpmteFd(p) != NULL) {
01435                     rpmVSFlags ovsflags = rpmtsVSFlags(ts);
01436                     rpmVSFlags vsflags = ovsflags | RPMVSF_NEEDPAYLOAD;
01437                     rpmRC rpmrc;
01438 
01439                     ovsflags = rpmtsSetVSFlags(ts, vsflags);
01440                     rpmrc = rpmReadPackageFile(ts, rpmteFd(p),
01441                                 rpmteNEVR(p), &p->h);
01442                     vsflags = rpmtsSetVSFlags(ts, ovsflags);
01443 
01444                     switch (rpmrc) {
01445                     default:
01446                         /*@-noeffectuncon@*/ /* FIX: notify annotations */
01447                         p->fd = ts->notify(p->h, RPMCALLBACK_INST_CLOSE_FILE,
01448                                         0, 0,
01449                                         rpmteKey(p), ts->notifyData);
01450                         /*@=noeffectuncon@*/
01451                         p->fd = NULL;
01452                         ourrc++;
01453                         /*@innerbreak@*/ break;
01454                     case RPMRC_NOTTRUSTED:
01455                     case RPMRC_NOKEY:
01456                     case RPMRC_OK:
01457                         /*@innerbreak@*/ break;
01458                     }
01459                     if (rpmteFd(p) != NULL) gotfd = 1;
01460                 }
01461             }
01462             /*@=type@*/
01463 
01464             if (rpmteFd(p) != NULL) {
01465                 /*
01466                  * XXX Sludge necessary to tranfer existing fstates/actions
01467                  * XXX around a recreated file info set.
01468                  */
01469                 psm->fi = rpmfiFree(psm->fi);
01470                 {
01471                     char * fstates = fi->fstates;
01472                     fileAction * actions = fi->actions;
01473                     rpmte savep;
01474 
01475                     fi->fstates = NULL;
01476                     fi->actions = NULL;
01477 /*@-nullstate@*/ /* FIX: fi->actions is NULL */
01478                     fi = rpmfiFree(fi);
01479 /*@=nullstate@*/
01480 
01481                     savep = rpmtsSetRelocateElement(ts, p);
01482                     fi = rpmfiNew(ts, p->h, RPMTAG_BASENAMES, 1);
01483                     (void) rpmtsSetRelocateElement(ts, savep);
01484 
01485                     if (fi != NULL) {   /* XXX can't happen */
01486                         fi->te = p;
01487                         fi->fstates = _free(fi->fstates);
01488                         fi->fstates = fstates;
01489                         fi->actions = _free(fi->actions);
01490                         fi->actions = actions;
01491                         p->fi = fi;
01492                     }
01493                 }
01494                 psm->fi = rpmfiLink(p->fi, NULL);
01495 
01496 /*@-nullstate@*/ /* FIX: psm->fi may be NULL */
01497                 if (rpmpsmStage(psm, PSM_PKGINSTALL)) {
01498                     ourrc++;
01499                     lastFailKey = pkgKey;
01500                 }
01501 /*@=nullstate@*/
01502             } else {
01503                 ourrc++;
01504                 lastFailKey = pkgKey;
01505             }
01506 
01507             if (gotfd) {
01508                 /*@-noeffectuncon @*/ /* FIX: check rc */
01509                 (void) ts->notify(p->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0,
01510                         rpmteKey(p), ts->notifyData);
01511                 /*@=noeffectuncon @*/
01512                 /*@-type@*/
01513                 p->fd = NULL;
01514                 /*@=type@*/
01515             }
01516 
01517             p->h = headerFree(p->h);
01518 
01519             (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_INSTALL), 0);
01520 
01521             /*@switchbreak@*/ break;
01522 
01523         case TR_REMOVED:
01524             (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_ERASE), 0);
01525 
01526             rpmMessage(RPMMESS_DEBUG, "========== --- %s %s-%s 0x%x\n",
01527                 rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p));
01528 
01529             /*
01530              * XXX This has always been a hack, now mostly broken.
01531              * If install failed, then we shouldn't erase.
01532              */
01533             if (rpmteDependsOnKey(p) != lastFailKey) {
01534                 if (rpmpsmStage(psm, PSM_PKGERASE))
01535                     ourrc++;
01536             }
01537 
01538             (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_ERASE), 0);
01539 
01540             /*@switchbreak@*/ break;
01541         }
01542         xx = rpmdbSync(rpmtsGetRdb(ts));
01543 
01544 /*@-nullstate@*/ /* FIX: psm->fi may be NULL */
01545         psm = rpmpsmFree(psm);
01546 /*@=nullstate@*/
01547 
01548 /*@-type@*/ /* FIX: p is almost opaque */
01549         p->fi = rpmfiFree(p->fi);
01550 /*@=type@*/
01551 
01552     }
01553     /*@=branchstate@*/
01554     pi = rpmtsiFree(pi);
01555 
01556     /*@-nullstate@*/ /* FIX: ts->flList may be NULL */
01557     if (ourrc)
01558         return -1;
01559     else
01560         return 0;
01561     /*@=nullstate@*/
01562 }

Generated on Sun Nov 21 17:08:38 2004 for rpm by doxygen 1.3.5