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

Generated on Sun Oct 26 13:02:01 2003 for rpm by doxygen1.2.18