3 * \file lib/transaction.c
9 #include <rpmmacro.h> /* XXX for rpmExpand */
17 #define _RPMFI_INTERNAL
20 #define _RPMTE_INTERNAL
23 #define _RPMTS_INTERNAL
28 #include "legacy.h" /* XXX domd5 */
29 #include "misc.h" /* XXX stripTrailingChar, splitString, currentDirectory */
33 /*@access FD_t @*/ /* XXX compared with NULL */
34 /*@access Header @*/ /* XXX compared with NULL */
35 /*@access rpmps @*/ /* XXX need rpmProblemSetOK() */
36 /*@access dbiIndexSet @*/
52 static int archOkay(/*@null@*/ const char * pkgArch)
55 if (pkgArch == NULL) return 0;
56 return (rpmMachineScore(RPM_MACHTABLE_INSTARCH, pkgArch) ? 1 : 0);
61 static int osOkay(/*@null@*/ const char * pkgOs)
64 if (pkgOs == NULL) return 0;
65 return (rpmMachineScore(RPM_MACHTABLE_INSTOS, pkgOs) ? 1 : 0);
70 static int sharedCmp(const void * one, const void * two)
73 sharedFileInfo a = (sharedFileInfo) one;
74 sharedFileInfo b = (sharedFileInfo) two;
76 if (a->otherPkg < b->otherPkg)
78 else if (a->otherPkg > b->otherPkg)
86 static fileAction decideFileFate(const rpmts ts,
87 const rpmfi ofi, rpmfi nfi)
88 /*@globals fileSystem @*/
89 /*@modifies nfi, fileSystem @*/
91 const char * fn = rpmfiFN(nfi);
92 int newFlags = rpmfiFFlags(nfi);
94 fileTypes dbWhat, newWhat, diskWhat;
96 int save = (newFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SAVE;
100 * The file doesn't exist on the disk. Create it unless the new
101 * package has marked it as missingok, or allfiles is requested.
103 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_ALLFILES)
104 && (newFlags & RPMFILE_MISSINGOK))
106 rpmMessage(RPMMESS_DEBUG, _("%s skipped due to missingok flag\n"),
114 diskWhat = whatis(sb.st_mode);
115 dbWhat = whatis(ofi->fmodes[ofi->i]);
116 newWhat = whatis(nfi->fmodes[nfi->i]);
119 * RPM >= 2.3.10 shouldn't create config directories -- we'll ignore
120 * them in older packages as well.
125 if (diskWhat != newWhat)
127 else if (newWhat != dbWhat && diskWhat != dbWhat)
129 else if (dbWhat != newWhat)
131 else if (dbWhat != LINK && dbWhat != REG)
135 * This order matters - we'd prefer to CREATE the file if at all
136 * possible in case something else (like the timestamp) has changed.
140 if (ofi->md5s != NULL && nfi->md5s != NULL) {
142 const unsigned char * omd5 = ofi->md5s + (16 * ofi->i);
143 const unsigned char * nmd5 = nfi->md5s + (16 * nfi->i);
144 if (domd5(fn, buffer, 0, NULL))
145 return FA_CREATE; /* assume file has been removed */
146 if (!memcmp(omd5, buffer, 16))
147 return FA_CREATE; /* unmodified config file, replace. */
148 if (!memcmp(omd5, nmd5, 16))
149 return FA_SKIP; /* identical file, don't bother. */
152 const char * omd5 = ofi->fmd5s[ofi->i];
153 const char * nmd5 = nfi->fmd5s[nfi->i];
154 if (domd5(fn, buffer, 1, NULL))
155 return FA_CREATE; /* assume file has been removed */
156 if (!strcmp(omd5, buffer))
157 return FA_CREATE; /* unmodified config file, replace. */
158 if (!strcmp(omd5, nmd5))
159 return FA_SKIP; /* identical file, don't bother. */
162 } else /* dbWhat == LINK */ {
163 memset(buffer, 0, sizeof(buffer));
164 if (readlink(fn, buffer, sizeof(buffer) - 1) == -1)
165 return FA_CREATE; /* assume file has been removed */
166 if (!strcmp(ofi->flinks[ofi->i], buffer))
167 return FA_CREATE; /* unmodified config file, replace. */
168 if (!strcmp(ofi->flinks[ofi->i], nfi->flinks[nfi->i]))
169 return FA_SKIP; /* identical file, don't bother. */
173 * The config file on the disk has been modified, but
174 * the ones in the two packages are different. It would
175 * be nice if RPM was smart enough to at least try and
176 * merge the difference ala CVS, but...
183 static int filecmp(rpmfi afi, rpmfi bfi)
186 fileTypes awhat = whatis(afi->fmodes[afi->i]);
187 fileTypes bwhat = whatis(bfi->fmodes[bfi->i]);
189 if (awhat != bwhat) return 1;
192 const char * alink = afi->flinks[afi->i];
193 const char * blink = bfi->flinks[bfi->i];
194 return strcmp(alink, blink);
195 } else if (awhat == REG) {
197 if (afi->md5s != NULL && bfi->md5s != NULL) {
199 const unsigned char * amd5 = afi->md5s + (16 * afi->i);
200 const unsigned char * bmd5 = bfi->md5s + (16 * bfi->i);
201 return memcmp(amd5, bmd5, 16);
204 const char * amd5 = afi->fmd5s[afi->i];
205 const char * bmd5 = bfi->fmd5s[bfi->i];
206 return strcmp(amd5, bmd5);
216 /* XXX only ts->{probs,rpmdb} modified */
218 static int handleInstInstalledFiles(const rpmts ts,
220 sharedFileInfo shared,
221 int sharedCount, int reportConflicts)
222 /*@globals fileSystem @*/
223 /*@modifies ts, fi, fileSystem @*/
225 const char * altNEVR = NULL;
226 rpmfi otherFi = NULL;
231 { rpmdbMatchIterator mi;
235 mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
236 &shared->otherPkg, sizeof(shared->otherPkg));
237 while ((h = rpmdbNextIterator(mi)) != NULL) {
238 altNEVR = hGetNEVR(h, NULL);
239 otherFi = rpmfiNew(ts, NULL, h, RPMTAG_BASENAMES, scareMem);
242 mi = rpmdbFreeIterator(mi);
248 fi->replaced = xcalloc(sharedCount, sizeof(*fi->replaced));
250 ps = rpmtsProblems(ts);
251 for (i = 0; i < sharedCount; i++, shared++) {
252 int otherFileNum, fileNum;
254 otherFileNum = shared->otherFileNum;
255 (void) rpmfiSetFX(otherFi, otherFileNum);
257 fileNum = shared->pkgFileNum;
258 (void) rpmfiSetFX(fi, fileNum);
261 /* XXX another tedious segfault, assume file state normal. */
262 if (otherStates && otherStates[otherFileNum] != RPMFILE_STATE_NORMAL)
266 if (XFA_SKIPPING(fi->actions[fileNum]))
269 if (filecmp(otherFi, fi)) {
270 if (reportConflicts) {
271 rpmpsAppend(ps, RPMPROB_FILE_CONFLICT,
272 rpmteNEVR(p), rpmteKey(p),
273 rpmfiDN(fi), rpmfiBN(fi),
277 if (!(rpmfiFFlags(otherFi) | rpmfiFFlags(fi)) & RPMFILE_CONFIG) {
278 /*@-assignexpose@*/ /* FIX: p->replaced, not fi */
279 if (!shared->isRemoved)
280 fi->replaced[numReplaced++] = *shared;
285 if ((rpmfiFFlags(otherFi) | rpmfiFFlags(fi)) & RPMFILE_CONFIG) {
287 action = decideFileFate(ts, otherFi, fi);
288 fi->actions[fileNum] = action;
290 fi->replacedSizes[fileNum] = otherFi->fsizes[otherFi->i];
295 altNEVR = _free(altNEVR);
296 otherFi = rpmfiFree(otherFi, 1);
298 fi->replaced = xrealloc(fi->replaced, /* XXX memory leak */
299 sizeof(*fi->replaced) * (numReplaced + 1));
300 fi->replaced[numReplaced].otherPkg = 0;
308 /* XXX only ts->rpmdb modified */
309 static int handleRmvdInstalledFiles(const rpmts ts, rpmfi fi,
310 sharedFileInfo shared, int sharedCount)
311 /*@globals fileSystem @*/
312 /*@modifies ts, fi, fileSystem @*/
316 const char * otherStates;
319 rpmdbMatchIterator mi;
321 mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
322 &shared->otherPkg, sizeof(shared->otherPkg));
323 h = rpmdbNextIterator(mi);
325 mi = rpmdbFreeIterator(mi);
329 xx = hge(h, RPMTAG_FILESTATES, NULL, (void **) &otherStates, NULL);
332 for (i = 0; i < sharedCount; i++, shared++) {
333 int otherFileNum, fileNum;
334 otherFileNum = shared->otherFileNum;
335 fileNum = shared->pkgFileNum;
337 if (otherStates[otherFileNum] != RPMFILE_STATE_NORMAL)
340 fi->actions[fileNum] = FA_SKIP;
344 mi = rpmdbFreeIterator(mi);
349 #define ISROOT(_d) (((_d)[0] == '/' && (_d)[1] == '\0') ? "" : (_d))
352 static int _fps_debug = 0;
354 static int fpsCompare (const void * one, const void * two)
357 const struct fingerPrint_s * a = (const struct fingerPrint_s *)one;
358 const struct fingerPrint_s * b = (const struct fingerPrint_s *)two;
359 int adnlen = strlen(a->entry->dirName);
360 int asnlen = (a->subDir ? strlen(a->subDir) : 0);
361 int abnlen = strlen(a->baseName);
362 int bdnlen = strlen(b->entry->dirName);
363 int bsnlen = (b->subDir ? strlen(b->subDir) : 0);
364 int bbnlen = strlen(b->baseName);
365 char * afn, * bfn, * t;
368 if (adnlen == 1 && asnlen != 0) adnlen = 0;
369 if (bdnlen == 1 && bsnlen != 0) bdnlen = 0;
372 afn = t = alloca(adnlen+asnlen+abnlen+2);
373 if (adnlen) t = stpcpy(t, a->entry->dirName);
375 if (a->subDir && asnlen) t = stpcpy(t, a->subDir);
376 if (abnlen) t = stpcpy(t, a->baseName);
377 if (afn[0] == '/' && afn[1] == '/') afn++;
379 bfn = t = alloca(bdnlen+bsnlen+bbnlen+2);
380 if (bdnlen) t = stpcpy(t, b->entry->dirName);
382 if (b->subDir && bsnlen) t = stpcpy(t, b->subDir);
383 if (bbnlen) t = stpcpy(t, b->baseName);
384 if (bfn[0] == '/' && bfn[1] == '/') bfn++;
387 rc = strcmp(afn, bfn);
390 fprintf(stderr, "\trc(%d) = strcmp(\"%s\", \"%s\")\n", rc, afn, bfn);
395 fprintf(stderr, "\t%s/%s%s\trc %d\n",
396 ISROOT(b->entry->dirName),
397 (b->subDir ? b->subDir : ""),
407 static int _linear_fps_search = 0;
409 static int findFps(const struct fingerPrint_s * fiFps,
410 const struct fingerPrint_s * otherFps,
418 fprintf(stderr, "==> %s/%s%s\n",
419 ISROOT(fiFps->entry->dirName),
420 (fiFps->subDir ? fiFps->subDir : ""),
424 if (_linear_fps_search) {
427 for (otherFileNum = 0; otherFileNum < otherFc; otherFileNum++, otherFps++) {
431 fprintf(stderr, "\t%4d %s/%s%s\n", otherFileNum,
432 ISROOT(otherFps->entry->dirName),
433 (otherFps->subDir ? otherFps->subDir : ""),
437 /* If the addresses are the same, so are the values. */
438 if (fiFps == otherFps)
441 /* Otherwise, compare fingerprints by value. */
442 /*@-nullpass@*/ /* LCL: looks good to me */
443 if (FP_EQUAL((*fiFps), (*otherFps)))
448 if (otherFileNum == otherFc) {
451 fprintf(stderr, "*** NULL %s/%s%s\n",
452 ISROOT(fiFps->entry->dirName),
453 (fiFps->subDir ? fiFps->subDir : ""),
462 const struct fingerPrint_s * bingoFps;
465 bingoFps = bsearch(fiFps, otherFps, otherFc, sizeof(*otherFps), fpsCompare);
467 if (bingoFps == NULL) {
469 fprintf(stderr, "*** NULL %s/%s%s\n",
470 ISROOT(fiFps->entry->dirName),
471 (fiFps->subDir ? fiFps->subDir : ""),
477 /* If the addresses are the same, so are the values. */
478 /*@-nullpass@*/ /* LCL: looks good to me */
479 if (!(fiFps == bingoFps || FP_EQUAL((*fiFps), (*bingoFps)))) {
481 fprintf(stderr, "*** BAD %s/%s%s\n",
482 ISROOT(bingoFps->entry->dirName),
483 (bingoFps->subDir ? bingoFps->subDir : ""),
489 otherFileNum = (bingoFps != NULL ? (bingoFps - otherFps) : 0);
497 * Update disk space needs on each partition for this package's files.
499 /* XXX only ts->{probs,di} modified */
500 static void handleOverlappedFiles(const rpmts ts,
501 const rpmte p, rpmfi fi)
502 /*@globals fileSystem @*/
503 /*@modifies ts, fi, fileSystem @*/
505 uint_32 fixupSize = 0;
510 ps = rpmtsProblems(ts);
511 fi = rpmfiInit(fi, 0);
513 while ((i = rpmfiNext(fi)) >= 0) {
514 struct fingerPrint_s * fiFps;
515 int otherPkgNum, otherFileNum;
520 if (XFA_SKIPPING(fi->actions[i]))
529 * Retrieve all records that apply to this file. Note that the
530 * file info records were built in the same order as the packages
531 * will be installed and removed so the records for an overlapped
532 * files will be sorted in exactly the same order.
534 (void) htGetEntry(ts->ht, fiFps,
535 (const void ***) &recs, &numRecs, NULL);
538 * If this package is being added, look only at other packages
539 * being added -- removed packages dance to a different tune.
541 * If both this and the other package are being added, overlapped
542 * files must be identical (or marked as a conflict). The
543 * disposition of already installed config files leads to
544 * a small amount of extra complexity.
546 * If this package is being removed, then there are two cases that
547 * need to be worried about:
548 * If the other package is being added, then skip any overlapped files
549 * so that this package removal doesn't nuke the overlapped files
550 * that were just installed.
551 * If both this and the other package are being removed, then each
552 * file removal from preceding packages needs to be skipped so that
553 * the file removal occurs only on the last occurence of an overlapped
554 * file in the transaction set.
558 /* Locate this overlapped file in the set of added/removed packages. */
559 for (j = 0; j < numRecs && recs[j] != fi; j++)
562 /* Find what the previous disposition of this file was. */
563 otherFileNum = -1; /* keep gcc quiet */
565 for (otherPkgNum = j - 1; otherPkgNum >= 0; otherPkgNum--) {
566 struct fingerPrint_s * otherFps;
569 otherFi = recs[otherPkgNum];
571 /* Added packages need only look at other added packages. */
572 if (rpmteType(p) == TR_ADDED && rpmteType(otherFi->te) != TR_ADDED)
573 /*@innercontinue@*/ continue;
575 otherFps = otherFi->fps;
576 otherFc = rpmfiFC(otherFi);
578 otherFileNum = findFps(fiFps, otherFps, otherFc);
579 (void) rpmfiSetFX(otherFi, otherFileNum);
581 /* XXX Happens iff fingerprint for incomplete package install. */
582 if (otherFi->actions[otherFileNum] != FA_UNKNOWN)
583 /*@innerbreak@*/ break;
587 switch (rpmteType(p)) {
590 if (otherPkgNum < 0) {
591 /* XXX is this test still necessary? */
592 if (fi->actions[i] != FA_UNKNOWN)
593 /*@switchbreak@*/ break;
594 if ((rpmfiFFlags(fi) & RPMFILE_CONFIG) &&
596 /* Here is a non-overlapped pre-existing config file. */
597 fi->actions[i] = (rpmfiFFlags(fi) & RPMFILE_NOREPLACE)
598 ? FA_ALTNAME : FA_BACKUP;
600 fi->actions[i] = FA_CREATE;
602 /*@switchbreak@*/ break;
605 assert(otherFi != NULL);
606 /* Mark added overlapped non-identical files as a conflict. */
607 if ((rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACENEWFILES)
608 && filecmp(otherFi, fi))
610 rpmpsAppend(ps, RPMPROB_NEW_FILE_CONFLICT,
611 rpmteNEVR(p), rpmteKey(p),
613 rpmteNEVR(otherFi->te),
617 /* Try to get the disk accounting correct even if a conflict. */
618 fixupSize = otherFi->fsizes[otherFileNum];
620 if ((rpmfiFFlags(fi) & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
621 /* Here is an overlapped pre-existing config file. */
622 fi->actions[i] = (rpmfiFFlags(fi) & RPMFILE_NOREPLACE)
623 ? FA_ALTNAME : FA_SKIP;
625 fi->actions[i] = FA_CREATE;
627 } /*@switchbreak@*/ break;
630 if (otherPkgNum >= 0) {
631 assert(otherFi != NULL);
632 /* Here is an overlapped added file we don't want to nuke. */
633 if (otherFi->actions[otherFileNum] != FA_ERASE) {
634 /* On updates, don't remove files. */
635 fi->actions[i] = FA_SKIP;
636 /*@switchbreak@*/ break;
638 /* Here is an overlapped removed file: skip in previous. */
639 otherFi->actions[otherFileNum] = FA_SKIP;
641 if (XFA_SKIPPING(fi->actions[i]))
642 /*@switchbreak@*/ break;
643 if (fi->fstates && fi->fstates[i] != RPMFILE_STATE_NORMAL)
644 /*@switchbreak@*/ break;
645 if (!(S_ISREG(fi->fmodes[i]) && (rpmfiFFlags(fi) & RPMFILE_CONFIG))) {
646 fi->actions[i] = FA_ERASE;
647 /*@switchbreak@*/ break;
650 /* Here is a pre-existing modified config file that needs saving. */
652 const unsigned char * md5 = fi->md5s + (16 * i);
653 if (!domd5(fn, md5sum, 0, NULL) && memcmp(md5, md5sum, 16)) {
654 fi->actions[i] = FA_BACKUP;
655 /*@switchbreak@*/ break;
658 fi->actions[i] = FA_ERASE;
659 /*@switchbreak@*/ break;
663 /* Update disk space info for a file. */
664 rpmtsUpdateDSI(ts, fi->fps[i].entry->dev,
665 fi->fsizes[i], fi->replacedSizes[i], fixupSize, fi->actions[i]);
672 * Ensure that current package is newer than installed package.
673 * @param ts transaction set
674 * @param p current transaction element
675 * @param h installed header
676 * @return 0 if not newer, 1 if okay
678 static int ensureOlder(rpmts ts,
679 const rpmte p, const Header h)
682 int_32 reqFlags = (RPMSENSE_LESS | RPMSENSE_EQUAL);
689 if (p == NULL || h == NULL)
693 nb = strlen(rpmteNEVR(p)) + (rpmteE(p) != NULL ? strlen(rpmteE(p)) : 0) + 1;
697 if (rpmteE(p) != NULL) t = stpcpy( stpcpy(t, rpmteE(p)), ":");
698 if (rpmteV(p) != NULL) t = stpcpy(t, rpmteV(p));
700 if (rpmteR(p) != NULL) t = stpcpy(t, rpmteR(p));
703 req = rpmdsSingle(RPMTAG_REQUIRENAME, rpmteN(p), reqEVR, reqFlags);
704 rc = headerMatchesDepFlags(h, req);
705 req = rpmdsFree(req);
708 rpmps ps = rpmtsProblems(ts);
709 const char * altNEVR = hGetNEVR(h, NULL);
710 rpmpsAppend(ps, RPMPROB_OLDPACKAGE,
711 rpmteNEVR(p), rpmteKey(p),
715 altNEVR = _free(altNEVR);
726 /*@-mustmod@*/ /* FIX: fi->actions is modified. */
728 static void skipFiles(const rpmts ts, rpmfi fi)
729 /*@globals rpmGlobalMacroContext @*/
730 /*@modifies fi, rpmGlobalMacroContext @*/
732 int noDocs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NODOCS);
733 char ** netsharedPaths = NULL;
734 const char ** languages;
735 const char * dn, * bn;
736 int dnlen, bnlen, ix;
744 noDocs = rpmExpandNumeric("%{_excludedocs}");
746 { const char *tmpPath = rpmExpand("%{_netsharedpath}", NULL);
748 if (tmpPath && *tmpPath != '%')
749 netsharedPaths = splitString(tmpPath, strlen(tmpPath), ':');
751 tmpPath = _free(tmpPath);
754 s = rpmExpand("%{_install_langs}", NULL);
756 if (!(s && *s != '%'))
759 languages = (const char **) splitString(s, strlen(s), ':');
765 /* Compute directory refcount, skip directory if now empty. */
767 drc = alloca(dc * sizeof(*drc));
768 memset(drc, 0, dc * sizeof(*drc));
769 dff = alloca(dc * sizeof(*dff));
770 memset(dff, 0, dc * sizeof(*dff));
772 fi = rpmfiInit(fi, 0);
773 if (fi != NULL) /* XXX lclint */
774 while ((i = rpmfiNext(fi)) >= 0)
784 continue; /* XXX can't happen */
788 /* Don't bother with skipped files */
789 if (XFA_SKIPPING(fi->actions[i])) {
795 * Skip net shared paths.
796 * Net shared paths are not relative to the current root (though
797 * they do need to take package relocations into account).
799 for (nsp = netsharedPaths; nsp && *nsp; nsp++) {
804 if (strncmp(dn, *nsp, len))
805 /*@innercontinue@*/ continue;
806 /* Only directories or complete file paths can be net shared */
807 if (!(dn[len] == '/' || dn[len] == '\0'))
808 /*@innercontinue@*/ continue;
810 if (len < (dnlen + bnlen))
811 /*@innercontinue@*/ continue;
812 if (strncmp(dn, *nsp, dnlen))
813 /*@innercontinue@*/ continue;
814 if (strncmp(bn, (*nsp) + dnlen, bnlen))
815 /*@innercontinue@*/ continue;
817 /* Only directories or complete file paths can be net shared */
818 if (!((*nsp)[len] == '/' || (*nsp)[len] == '\0'))
819 /*@innercontinue@*/ continue;
822 /*@innerbreak@*/ break;
826 drc[ix]--; dff[ix] = 1;
827 fi->actions[i] = FA_SKIPNETSHARED;
832 * Skip i18n language specific files.
834 if (fi->flangs && languages && *fi->flangs[i]) {
835 const char **lang, *l, *le;
836 for (lang = languages; *lang != NULL; lang++) {
837 if (!strcmp(*lang, "all"))
838 /*@innerbreak@*/ break;
839 for (l = fi->flangs[i]; *l != '\0'; l = le) {
840 for (le = l; *le != '\0' && *le != '|'; le++)
842 if ((le-l) > 0 && !strncmp(*lang, l, (le-l)))
843 /*@innerbreak@*/ break;
844 if (*le == '|') le++; /* skip over | */
847 /*@innerbreak@*/ break;
850 drc[ix]--; dff[ix] = 1;
851 fi->actions[i] = FA_SKIPNSTATE;
857 * Skip documentation if requested.
859 if (noDocs && (rpmfiFFlags(fi) & RPMFILE_DOC)) {
860 drc[ix]--; dff[ix] = 1;
861 fi->actions[i] = FA_SKIPNSTATE;
866 /* Skip (now empty) directories that had skipped files. */
868 if (fi != NULL) /* XXX can't happen */
869 for (j = 0; j < dc; j++)
871 if ((fi = rpmfiInitD(fi)) != NULL)
872 while (j = rpmfiNextD(fi) >= 0)
876 if (drc[j]) continue; /* dir still has files. */
877 if (!dff[j]) continue; /* dir was not emptied here. */
879 /* Find parent directory and basename. */
880 dn = fi->dnl[j]; dnlen = strlen(dn) - 1;
881 bn = dn + dnlen; bnlen = 0;
882 while (bn > dn && bn[-1] != '/') {
888 /* If explicitly included in the package, skip the directory. */
889 fi = rpmfiInit(fi, 0);
890 if (fi != NULL) /* XXX lclint */
891 while ((i = rpmfiNext(fi)) >= 0) {
894 if (XFA_SKIPPING(fi->actions[i]))
895 /*@innercontinue@*/ continue;
896 if (whatis(fi->fmodes[i]) != XDIR)
897 /*@innercontinue@*/ continue;
898 dir = fi->dnl[fi->dil[i]];
899 if (strlen(dir) != dnlen)
900 /*@innercontinue@*/ continue;
901 if (strncmp(dir, dn, dnlen))
902 /*@innercontinue@*/ continue;
903 if (strlen(fi->bnl[i]) != bnlen)
904 /*@innercontinue@*/ continue;
905 if (strncmp(fi->bnl[i], bn, bnlen))
906 /*@innercontinue@*/ continue;
907 rpmMessage(RPMMESS_DEBUG, _("excluding directory %s\n"), dn);
908 fi->actions[i] = FA_SKIPNSTATE;
909 /*@innerbreak@*/ break;
913 if (netsharedPaths) freeSplitString(netsharedPaths);
914 #ifdef DYING /* XXX freeFi will deal with this later. */
915 fi->flangs = _free(fi->flangs);
917 if (languages) freeSplitString((char **)languages);
923 * Return transaction element's file info.
924 * @todo Take a rpmfi refcount here.
925 * @param tsi transaction element iterator
926 * @return transaction element file info
929 rpmfi rpmtsiFi(const rpmtsi tsi)
934 if (tsi != NULL && tsi->ocsave != -1) {
935 /*@-type -abstract@*/ /* FIX: rpmte not opaque */
936 rpmte te = rpmtsElement(tsi->ts, tsi->ocsave);
938 if (te != NULL && (fi = te->fi) != NULL)
941 /*@=type =abstract@*/
943 /*@-compdef -refcounttrans -usereleased @*/
945 /*@=compdef =refcounttrans =usereleased @*/
948 #define NOTIFY(_ts, _al) /*@i@*/ if ((_ts)->notify) (void) (_ts)->notify _al
950 int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
954 int totalFileCount = 0;
956 sharedFileInfo shared, sharedList;
960 fingerPrintCache fpc;
962 PSM_t psm = memset(alloca(sizeof(*psm)), 0, sizeof(*psm));
967 /* FIXME: what if the same package is included in ts twice? */
969 if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS)
970 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
971 if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERS)
972 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransTriggers));
974 /* XXX MULTILIB is broken, as packages can and do execute /sbin/ldconfig. */
975 if (rpmtsFlags(ts) & (RPMTRANS_FLAG_JUSTDB | RPMTRANS_FLAG_MULTILIB))
976 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
978 ts->probs = rpmpsFree(ts->probs);
979 ts->probs = rpmpsCreate();
981 /* XXX Make sure the database is open RDWR for package install/erase. */
982 { int dbmode = (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
983 ? O_RDONLY : (O_RDWR|O_CREAT);
985 /* Open database RDWR for installing packages. */
986 if (rpmtsOpenDB(ts, dbmode))
987 return -1; /* XXX W2DO? */
990 ts->ignoreSet = ignoreSet;
991 { const char * currDir = currentDirectory();
992 rpmtsSetCurrDir(ts, currDir);
993 currDir = _free(currDir);
996 (void) rpmtsSetChrootDone(ts, 0);
998 { int_32 tid = (int_32) time(NULL);
999 (void) rpmtsSetTid(ts, tid);
1002 memset(psm, 0, sizeof(*psm));
1003 psm->ts = rpmtsLink(ts, "tsRun");
1005 /* Get available space on mounted file systems. */
1006 xx = rpmtsInitDSI(ts);
1008 /* ===============================================
1009 * For packages being installed:
1010 * - verify package arch/os.
1011 * - verify package epoch:version-release is newer.
1013 * For packages being removed:
1016 ps = rpmtsProblems(ts);
1017 /* The ordering doesn't matter here */
1018 pi = rpmtsiInit(ts);
1019 while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) {
1020 rpmdbMatchIterator mi;
1023 if ((fi = rpmtsiFi(pi)) == NULL)
1024 continue; /* XXX can't happen */
1027 if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREARCH))
1028 if (!archOkay(rpmteA(p)))
1029 rpmpsAppend(ps, RPMPROB_BADARCH,
1030 rpmteNEVR(p), rpmteKey(p),
1034 if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREOS))
1035 if (!osOkay(rpmteO(p)))
1036 rpmpsAppend(ps, RPMPROB_BADOS,
1037 rpmteNEVR(p), rpmteKey(p),
1041 if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_OLDPACKAGE)) {
1043 mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0);
1044 while ((h = rpmdbNextIterator(mi)) != NULL)
1045 xx = ensureOlder(ts, p, h);
1046 mi = rpmdbFreeIterator(mi);
1049 /* XXX multilib should not display "already installed" problems */
1050 if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEPKG) && !rpmteMultiLib(p)) {
1051 mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0);
1052 xx = rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_DEFAULT,
1054 xx = rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_DEFAULT,
1057 while (rpmdbNextIterator(mi) != NULL) {
1058 rpmpsAppend(ps, RPMPROB_PKG_INSTALLED,
1059 rpmteNEVR(p), rpmteKey(p),
1062 /*@innerbreak@*/ break;
1064 mi = rpmdbFreeIterator(mi);
1067 /* Count no. of files (if any). */
1068 totalFileCount += fc;
1071 pi = rpmtsiFree(pi);
1074 /* The ordering doesn't matter here */
1075 pi = rpmtsiInit(ts);
1076 while ((p = rpmtsiNext(pi, TR_REMOVED)) != NULL) {
1079 if ((fi = rpmtsiFi(pi)) == NULL)
1080 continue; /* XXX can't happen */
1083 totalFileCount += fc;
1085 pi = rpmtsiFree(pi);
1087 /* ===============================================
1088 * Initialize transaction element file info for package:
1092 * FIXME?: we'd be better off assembling one very large file list and
1093 * calling fpLookupList only once. I'm not sure that the speedup is
1094 * worth the trouble though.
1096 pi = rpmtsiInit(ts);
1097 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1100 if ((fi = rpmtsiFi(pi)) == NULL)
1101 continue; /* XXX can't happen */
1104 #ifdef DYING /* XXX W2DO? this is now done in rpmtsiFi, okay ??? */
1105 fi->magic = RPMFIMAGIC;
1110 switch (rpmteType(p)) {
1113 /* Skip netshared paths, not our i18n files, and excluded docs */
1116 /*@switchbreak@*/ break;
1118 fi->record = rpmteDBOffset(p);
1119 /*@switchbreak@*/ break;
1123 fi->fps = (fc > 0 ? xmalloc(fc * sizeof(*fi->fps)) : NULL);
1125 pi = rpmtsiFree(pi);
1127 if (!rpmtsChrootDone(ts)) {
1128 const char * rootDir = rpmtsRootDir(ts);
1130 /*@-superuser -noeffect @*/
1131 if (rootDir != NULL)
1132 xx = chroot(rootDir);
1133 /*@=superuser =noeffect @*/
1134 (void) rpmtsSetChrootDone(ts, 1);
1137 ts->ht = htCreate(totalFileCount * 2, 0, 0, fpHashFunction, fpEqual);
1138 fpc = fpCacheCreate(totalFileCount);
1140 /* ===============================================
1141 * Add fingerprint for each file not skipped.
1143 pi = rpmtsiInit(ts);
1144 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1147 if ((fi = rpmtsiFi(pi)) == NULL)
1148 continue; /* XXX can't happen */
1151 fpLookupList(fpc, fi->dnl, fi->bnl, fi->dil, fc, fi->fps);
1153 fi = rpmfiInit(fi, 0);
1154 if (fi != NULL) /* XXX lclint */
1155 while ((i = rpmfiNext(fi)) >= 0) {
1156 if (XFA_SKIPPING(fi->actions[i]))
1157 /*@innercontinue@*/ continue;
1158 /*@-dependenttrans@*/
1159 htAddEntry(ts->ht, fi->fps + i, (void *) fi);
1160 /*@=dependenttrans@*/
1164 pi = rpmtsiFree(pi);
1166 NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_START, 6, ts->orderCount,
1167 NULL, ts->notifyData));
1169 /* ===============================================
1170 * Compute file disposition for each package in transaction set.
1172 ps = rpmtsProblems(ts);
1173 pi = rpmtsiInit(ts);
1174 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1175 dbiIndexSet * matches;
1179 if ((fi = rpmtsiFi(pi)) == NULL)
1180 continue; /* XXX can't happen */
1183 NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_PROGRESS, rpmtsiOc(pi),
1184 ts->orderCount, NULL, ts->notifyData));
1186 if (fc == 0) continue;
1188 /* Extract file info for all files in this package from the database. */
1189 matches = xcalloc(fc, sizeof(*matches));
1190 if (rpmdbFindFpList(rpmtsGetRdb(ts), fi->fps, matches, fc)) {
1191 psm->ts = rpmtsUnlink(ts, "tsRun (rpmFindFpList fail)");
1193 return 1; /* XXX WTFO? */
1197 fi = rpmfiInit(fi, 0);
1198 while ((i = rpmfiNext(fi)) >= 0)
1199 numShared += dbiIndexSetCount(matches[i]);
1201 /* Build sorted file info list for this package. */
1202 shared = sharedList = xcalloc((numShared + 1), sizeof(*sharedList));
1204 fi = rpmfiInit(fi, 0);
1205 while ((i = rpmfiNext(fi)) >= 0) {
1207 * Take care not to mark files as replaced in packages that will
1208 * have been removed before we will get here.
1210 for (j = 0; j < dbiIndexSetCount(matches[i]); j++) {
1212 ro = dbiIndexRecordOffset(matches[i], j);
1214 qi = rpmtsiInit(ts);
1215 while ((q = rpmtsiNext(qi, TR_REMOVED)) != NULL) {
1217 /*@innerbreak@*/ break;
1218 if (rpmteDBOffset(q) == ro)
1221 qi = rpmtsiFree(qi);
1223 shared->pkgFileNum = i;
1224 shared->otherPkg = dbiIndexRecordOffset(matches[i], j);
1225 shared->otherFileNum = dbiIndexRecordFileNumber(matches[i], j);
1226 shared->isRemoved = (knownBad == ro);
1229 matches[i] = dbiFreeIndexSet(matches[i]);
1231 numShared = shared - sharedList;
1232 shared->otherPkg = -1;
1233 matches = _free(matches);
1235 /* Sort file info by other package index (otherPkg) */
1236 qsort(sharedList, numShared, sizeof(*shared), sharedCmp);
1238 /* For all files from this package that are in the database ... */
1240 for (i = 0; i < numShared; i = nexti) {
1243 shared = sharedList + i;
1245 /* Find the end of the files in the other package. */
1246 for (nexti = i + 1; nexti < numShared; nexti++) {
1247 if (sharedList[nexti].otherPkg != shared->otherPkg)
1248 /*@innerbreak@*/ break;
1251 /* Is this file from a package being removed? */
1253 if (ts->removedPackages != NULL)
1254 for (j = 0; j < ts->numRemovedPackages; j++) {
1255 if (ts->removedPackages[j] != shared->otherPkg)
1256 /*@innercontinue@*/ continue;
1258 /*@innerbreak@*/ break;
1261 /* Determine the fate of each file. */
1262 switch (rpmteType(p)) {
1264 xx = handleInstInstalledFiles(ts, p, fi, shared, nexti - i,
1265 !(beingRemoved || (rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEOLDFILES)));
1266 /*@switchbreak@*/ break;
1269 xx = handleRmvdInstalledFiles(ts, fi, shared, nexti - i);
1270 /*@switchbreak@*/ break;
1277 /* Update disk space needs on each partition for this package. */
1278 handleOverlappedFiles(ts, p, fi);
1280 /* Check added package has sufficient space on each partition used. */
1281 switch (rpmteType(p)) {
1283 rpmtsCheckDSIProblems(ts, p);
1284 /*@switchbreak@*/ break;
1286 /*@switchbreak@*/ break;
1289 pi = rpmtsiFree(pi);
1292 if (rpmtsChrootDone(ts)) {
1293 const char * currDir = rpmtsCurrDir(ts);
1294 /*@-superuser -noeffect @*/
1296 /*@=superuser =noeffect @*/
1297 (void) rpmtsSetChrootDone(ts, 0);
1298 if (currDir != NULL)
1299 xx = chdir(currDir);
1302 NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_STOP, 6, ts->orderCount,
1303 NULL, ts->notifyData));
1305 /* ===============================================
1306 * Free unused memory as soon as possible.
1308 pi = rpmtsiInit(ts);
1309 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1310 if ((fi = rpmtsiFi(pi)) == NULL)
1311 continue; /* XXX can't happen */
1312 if (rpmfiFC(fi) == 0)
1314 fi->fps = _free(fi->fps);
1316 pi = rpmtsiFree(pi);
1318 fpc = fpCacheFree(fpc);
1319 ts->ht = htFree(ts->ht);
1321 /* ===============================================
1322 * If unfiltered problems exist, free memory and return.
1324 if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS)
1325 || (ts->probs->numProblems &&
1326 (okProbs != NULL || rpmpsTrim(ts->probs, okProbs)))
1329 if (psm->ts != NULL)
1330 psm->ts = rpmtsUnlink(psm->ts, "tsRun (problems)");
1331 return ts->orderCount;
1334 /* ===============================================
1335 * Save removed files before erasing.
1337 if (rpmtsFlags(ts) & (RPMTRANS_FLAG_DIRSTASH | RPMTRANS_FLAG_REPACKAGE)) {
1338 pi = rpmtsiInit(ts);
1339 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1341 switch (rpmteType(p)) {
1343 /*@switchbreak@*/ break;
1345 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_REPACKAGE))
1346 /*@switchbreak@*/ break;
1348 psm->fi = rpmfiLink(fi, "tsRepackage");
1349 xx = psmStage(psm, PSM_PKGSAVE);
1350 (void) rpmfiUnlink(fi, "tsRepackage");
1353 /*@switchbreak@*/ break;
1356 pi = rpmtsiFree(pi);
1359 /* ===============================================
1360 * Install and remove packages.
1362 lastKey = (alKey)-2; /* erased packages have -1 */
1363 pi = rpmtsiInit(ts);
1364 /*@-branchstate@*/ /* FIX: fi reload needs work */
1365 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1370 if ((fi = rpmtsiFi(pi)) == NULL)
1371 continue; /* XXX can't happen */
1374 psm->fi = rpmfiLink(fi, "tsInstall");
1375 switch (rpmteType(p)) {
1378 pkgKey = rpmteAddedKey(p);
1380 rpmMessage(RPMMESS_DEBUG, "========== +++ %s\n", rpmteNEVR(p));
1382 /*@-type@*/ /* FIX: rpmte not opaque */
1384 /*@-noeffectuncon@*/ /* FIX: notify annotations */
1385 p->fd = ts->notify(fi->h, RPMCALLBACK_INST_OPEN_FILE, 0, 0,
1386 rpmteKey(p), ts->notifyData);
1387 /*@=noeffectuncon@*/
1388 if (rpmteFd(p) != NULL) {
1391 rpmrc = rpmReadPackageFile(ts, rpmteFd(p),
1394 if (!(rpmrc == RPMRC_OK || rpmrc == RPMRC_BADSIZE)) {
1395 /*@-noeffectuncon@*/ /* FIX: notify annotations */
1396 p->fd = ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE,
1398 rpmteKey(p), ts->notifyData);
1399 /*@=noeffectuncon@*/
1403 if (rpmteFd(p) != NULL) gotfd = 1;
1408 if (rpmteFd(p) != NULL) {
1410 char * fstates = fi->fstates;
1411 fileAction * actions = fi->actions;
1415 psm->fi = rpmfiFree(psm->fi, 1);
1416 (void) rpmfiFree(fi, 0);
1418 fi->magic = RPMFIMAGIC;
1421 (void) rpmfiNew(ts, fi, p->h, RPMTAG_BASENAMES, 1);
1422 psm->fi = rpmfiLink(fi, "tsInstall");
1423 fi->fstates = _free(fi->fstates);
1424 fi->fstates = fstates;
1425 fi->actions = _free(fi->actions);
1426 fi->actions = actions;
1430 if (rpmteMultiLib(p))
1431 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_MULTILIB));
1433 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) & ~RPMTRANS_FLAG_MULTILIB));
1435 if (psmStage(psm, PSM_PKGINSTALL)) {
1439 fi->h = headerFree(fi->h, "TR_ADDED fi->h free");
1445 p->h = headerFree(p->h, "TR_ADDED h free");
1448 /*@-noeffectuncon @*/ /* FIX: check rc */
1449 (void) ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0,
1450 rpmteKey(p), ts->notifyData);
1451 /*@=noeffectuncon @*/
1456 /*@switchbreak@*/ break;
1458 rpmMessage(RPMMESS_DEBUG, "========== --- %s\n", rpmteNEVR(p));
1459 /* If install failed, then we shouldn't erase. */
1460 if (rpmteDependsOnKey(p) != lastKey) {
1461 if (psmStage(psm, PSM_PKGERASE))
1464 /*@switchbreak@*/ break;
1466 xx = rpmdbSync(rpmtsGetRdb(ts));
1467 (void) rpmfiUnlink(psm->fi, "tsInstall");
1470 /*@-type@*/ /* FIX: p is almost opaque */
1471 p->fi = rpmfiFree(fi, 1);
1475 pi = rpmtsiFree(pi);
1477 psm->ts = rpmtsUnlink(psm->ts, "tsRun");
1479 /*@-nullstate@*/ /* FIX: ts->flList may be NULL */