2 * \file lib/transaction.c
8 #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)
87 static fileAction decideFileFate(const rpmts ts,
88 const rpmfi ofi, rpmfi nfi)
89 /*@globals fileSystem, internalState @*/
90 /*@modifies nfi, fileSystem, internalState @*/
92 const char * fn = rpmfiFN(nfi);
93 int newFlags = rpmfiFFlags(nfi);
95 fileTypes dbWhat, newWhat, diskWhat;
97 int save = (newFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SAVE;
101 * The file doesn't exist on the disk. Create it unless the new
102 * package has marked it as missingok, or allfiles is requested.
104 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_ALLFILES)
105 && (newFlags & RPMFILE_MISSINGOK))
107 rpmMessage(RPMMESS_DEBUG, _("%s skipped due to missingok flag\n"),
115 diskWhat = whatis((int_16)sb.st_mode);
116 dbWhat = whatis(rpmfiFMode(ofi));
117 newWhat = whatis(rpmfiFMode(nfi));
120 * RPM >= 2.3.10 shouldn't create config directories -- we'll ignore
121 * them in older packages as well.
126 if (diskWhat != newWhat)
128 else if (newWhat != dbWhat && diskWhat != dbWhat)
130 else if (dbWhat != newWhat)
132 else if (dbWhat != LINK && dbWhat != REG)
136 * This order matters - we'd prefer to CREATE the file if at all
137 * possible in case something else (like the timestamp) has changed.
140 const unsigned char * omd5, * nmd5;
141 if (domd5(fn, buffer, 0, NULL))
142 return FA_CREATE; /* assume file has been removed */
143 omd5 = rpmfiMD5(ofi);
144 if (omd5 && !memcmp(omd5, buffer, 16))
145 return FA_CREATE; /* unmodified config file, replace. */
146 nmd5 = rpmfiMD5(nfi);
148 if (omd5 && nmd5 && !memcmp(omd5, nmd5, 16))
149 return FA_SKIP; /* identical file, don't bother. */
151 } else /* dbWhat == LINK */ {
152 const char * oFLink, * nFLink;
153 memset(buffer, 0, sizeof(buffer));
154 if (readlink(fn, buffer, sizeof(buffer) - 1) == -1)
155 return FA_CREATE; /* assume file has been removed */
156 oFLink = rpmfiFLink(ofi);
157 if (oFLink && !strcmp(oFLink, buffer))
158 return FA_CREATE; /* unmodified config file, replace. */
159 nFLink = rpmfiFLink(nfi);
161 if (oFLink && nFLink && !strcmp(oFLink, nFLink))
162 return FA_SKIP; /* identical file, don't bother. */
167 * The config file on the disk has been modified, but
168 * the ones in the two packages are different. It would
169 * be nice if RPM was smart enough to at least try and
170 * merge the difference ala CVS, but...
179 static int filecmp(rpmfi afi, rpmfi bfi)
182 fileTypes awhat = whatis(rpmfiFMode(afi));
183 fileTypes bwhat = whatis(rpmfiFMode(bfi));
185 if (awhat != bwhat) return 1;
188 const char * alink = rpmfiFLink(afi);
189 const char * blink = rpmfiFLink(bfi);
190 if (alink == blink) return 0;
191 if (alink == NULL) return 1;
192 if (blink == NULL) return -1;
193 return strcmp(alink, blink);
194 } else if (awhat == REG) {
195 const unsigned char * amd5 = rpmfiMD5(afi);
196 const unsigned char * bmd5 = rpmfiMD5(bfi);
197 if (amd5 == bmd5) return 0;
198 if (amd5 == NULL) return 1;
199 if (bmd5 == NULL) return -1;
200 return memcmp(amd5, bmd5, 16);
209 /* XXX only ts->{probs,rpmdb} modified */
211 static int handleInstInstalledFiles(const rpmts ts,
213 sharedFileInfo shared,
214 int sharedCount, int reportConflicts)
215 /*@globals rpmGlobalMacroContext, fileSystem, internalState @*/
216 /*@modifies ts, fi, rpmGlobalMacroContext, fileSystem, internalState @*/
218 const char * altNEVR = NULL;
219 rpmfi otherFi = NULL;
224 { rpmdbMatchIterator mi;
228 mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
229 &shared->otherPkg, sizeof(shared->otherPkg));
230 while ((h = rpmdbNextIterator(mi)) != NULL) {
231 altNEVR = hGetNEVR(h, NULL);
232 otherFi = rpmfiNew(ts, NULL, h, RPMTAG_BASENAMES, scareMem);
235 mi = rpmdbFreeIterator(mi);
241 fi->replaced = xcalloc(sharedCount, sizeof(*fi->replaced));
243 ps = rpmtsProblems(ts);
244 for (i = 0; i < sharedCount; i++, shared++) {
245 int otherFileNum, fileNum;
248 otherFileNum = shared->otherFileNum;
249 (void) rpmfiSetFX(otherFi, otherFileNum);
251 fileNum = shared->pkgFileNum;
252 (void) rpmfiSetFX(fi, fileNum);
254 isCfgFile = ((rpmfiFFlags(otherFi) | rpmfiFFlags(fi)) & RPMFILE_CONFIG);
257 /* XXX another tedious segfault, assume file state normal. */
258 if (otherStates && otherStates[otherFileNum] != RPMFILE_STATE_NORMAL)
262 if (XFA_SKIPPING(fi->actions[fileNum]))
265 if (filecmp(otherFi, fi)) {
266 if (reportConflicts) {
267 rpmpsAppend(ps, RPMPROB_FILE_CONFLICT,
268 rpmteNEVR(p), rpmteKey(p),
269 rpmfiDN(fi), rpmfiBN(fi),
274 /*@-assignexpose@*/ /* FIX: p->replaced, not fi */
275 if (!shared->isRemoved)
276 fi->replaced[numReplaced++] = *shared;
283 action = decideFileFate(ts, otherFi, fi);
284 fi->actions[fileNum] = action;
286 fi->replacedSizes[fileNum] = rpmfiFSize(otherFi);
290 altNEVR = _free(altNEVR);
291 otherFi = rpmfiFree(otherFi, 1);
293 fi->replaced = xrealloc(fi->replaced, /* XXX memory leak */
294 sizeof(*fi->replaced) * (numReplaced + 1));
295 fi->replaced[numReplaced].otherPkg = 0;
303 /* XXX only ts->rpmdb modified */
304 static int handleRmvdInstalledFiles(const rpmts ts, rpmfi fi,
305 sharedFileInfo shared, int sharedCount)
306 /*@globals rpmGlobalMacroContext, fileSystem, internalState @*/
307 /*@modifies ts, fi, rpmGlobalMacroContext, fileSystem, internalState @*/
311 const char * otherStates;
314 rpmdbMatchIterator mi;
316 mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES,
317 &shared->otherPkg, sizeof(shared->otherPkg));
318 h = rpmdbNextIterator(mi);
320 mi = rpmdbFreeIterator(mi);
324 xx = hge(h, RPMTAG_FILESTATES, NULL, (void **) &otherStates, NULL);
327 for (i = 0; i < sharedCount; i++, shared++) {
328 int otherFileNum, fileNum;
329 otherFileNum = shared->otherFileNum;
330 fileNum = shared->pkgFileNum;
332 if (otherStates[otherFileNum] != RPMFILE_STATE_NORMAL)
335 fi->actions[fileNum] = FA_SKIP;
339 mi = rpmdbFreeIterator(mi);
344 #define ISROOT(_d) (((_d)[0] == '/' && (_d)[1] == '\0') ? "" : (_d))
349 static int fpsCompare (const void * one, const void * two)
352 const struct fingerPrint_s * a = (const struct fingerPrint_s *)one;
353 const struct fingerPrint_s * b = (const struct fingerPrint_s *)two;
354 int adnlen = strlen(a->entry->dirName);
355 int asnlen = (a->subDir ? strlen(a->subDir) : 0);
356 int abnlen = strlen(a->baseName);
357 int bdnlen = strlen(b->entry->dirName);
358 int bsnlen = (b->subDir ? strlen(b->subDir) : 0);
359 int bbnlen = strlen(b->baseName);
360 char * afn, * bfn, * t;
363 if (adnlen == 1 && asnlen != 0) adnlen = 0;
364 if (bdnlen == 1 && bsnlen != 0) bdnlen = 0;
367 afn = t = alloca(adnlen+asnlen+abnlen+2);
368 if (adnlen) t = stpcpy(t, a->entry->dirName);
370 if (a->subDir && asnlen) t = stpcpy(t, a->subDir);
371 if (abnlen) t = stpcpy(t, a->baseName);
372 if (afn[0] == '/' && afn[1] == '/') afn++;
374 bfn = t = alloca(bdnlen+bsnlen+bbnlen+2);
375 if (bdnlen) t = stpcpy(t, b->entry->dirName);
377 if (b->subDir && bsnlen) t = stpcpy(t, b->subDir);
378 if (bbnlen) t = stpcpy(t, b->baseName);
379 if (bfn[0] == '/' && bfn[1] == '/') bfn++;
382 rc = strcmp(afn, bfn);
385 fprintf(stderr, "\trc(%d) = strcmp(\"%s\", \"%s\")\n", rc, afn, bfn);
390 fprintf(stderr, "\t%s/%s%s\trc %d\n",
391 ISROOT(b->entry->dirName),
392 (b->subDir ? b->subDir : ""),
402 static int _linear_fps_search = 0;
404 static int findFps(const struct fingerPrint_s * fiFps,
405 const struct fingerPrint_s * otherFps,
413 fprintf(stderr, "==> %s/%s%s\n",
414 ISROOT(fiFps->entry->dirName),
415 (fiFps->subDir ? fiFps->subDir : ""),
419 if (_linear_fps_search) {
422 for (otherFileNum = 0; otherFileNum < otherFc; otherFileNum++, otherFps++) {
426 fprintf(stderr, "\t%4d %s/%s%s\n", otherFileNum,
427 ISROOT(otherFps->entry->dirName),
428 (otherFps->subDir ? otherFps->subDir : ""),
432 /* If the addresses are the same, so are the values. */
433 if (fiFps == otherFps)
436 /* Otherwise, compare fingerprints by value. */
437 /*@-nullpass@*/ /* LCL: looks good to me */
438 if (FP_EQUAL((*fiFps), (*otherFps)))
443 if (otherFileNum == otherFc) {
446 fprintf(stderr, "*** FP_EQUAL NULL %s/%s%s\n",
447 ISROOT(fiFps->entry->dirName),
448 (fiFps->subDir ? fiFps->subDir : ""),
457 const struct fingerPrint_s * bingoFps;
460 bingoFps = bsearch(fiFps, otherFps, otherFc, sizeof(*otherFps), fpsCompare);
462 if (bingoFps == NULL) {
465 fprintf(stderr, "*** bingoFps NULL %s/%s%s\n",
466 ISROOT(fiFps->entry->dirName),
467 (fiFps->subDir ? fiFps->subDir : ""),
473 /* If the addresses are the same, so are the values. */
474 /*@-nullpass@*/ /* LCL: looks good to me */
475 if (!(fiFps == bingoFps || FP_EQUAL((*fiFps), (*bingoFps)))) {
478 fprintf(stderr, "*** BAD %s/%s%s\n",
479 ISROOT(bingoFps->entry->dirName),
480 (bingoFps->subDir ? bingoFps->subDir : ""),
486 otherFileNum = (bingoFps != NULL ? (bingoFps - otherFps) : 0);
494 * Update disk space needs on each partition for this package's files.
496 /* XXX only ts->{probs,di} modified */
497 static void handleOverlappedFiles(const rpmts ts,
498 const rpmte p, rpmfi fi)
499 /*@globals fileSystem, internalState @*/
500 /*@modifies ts, fi, fileSystem, internalState @*/
502 uint_32 fixupSize = 0;
507 ps = rpmtsProblems(ts);
508 fi = rpmfiInit(fi, 0);
510 while ((i = rpmfiNext(fi)) >= 0) {
511 struct fingerPrint_s * fiFps;
512 int otherPkgNum, otherFileNum;
519 if (XFA_SKIPPING(fi->actions[i]))
524 FFlags = rpmfiFFlags(fi);
525 FMode = rpmfiFMode(fi);
530 * Retrieve all records that apply to this file. Note that the
531 * file info records were built in the same order as the packages
532 * will be installed and removed so the records for an overlapped
533 * files will be sorted in exactly the same order.
535 (void) htGetEntry(ts->ht, fiFps,
536 (const void ***) &recs, &numRecs, NULL);
539 * If this package is being added, look only at other packages
540 * being added -- removed packages dance to a different tune.
542 * If both this and the other package are being added, overlapped
543 * files must be identical (or marked as a conflict). The
544 * disposition of already installed config files leads to
545 * a small amount of extra complexity.
547 * If this package is being removed, then there are two cases that
548 * need to be worried about:
549 * If the other package is being added, then skip any overlapped files
550 * so that this package removal doesn't nuke the overlapped files
551 * that were just installed.
552 * If both this and the other package are being removed, then each
553 * file removal from preceding packages needs to be skipped so that
554 * the file removal occurs only on the last occurence of an overlapped
555 * file in the transaction set.
559 /* Locate this overlapped file in the set of added/removed packages. */
560 for (j = 0; j < numRecs && recs[j] != fi; j++)
563 /* Find what the previous disposition of this file was. */
564 otherFileNum = -1; /* keep gcc quiet */
566 for (otherPkgNum = j - 1; otherPkgNum >= 0; otherPkgNum--) {
567 struct fingerPrint_s * otherFps;
570 otherFi = recs[otherPkgNum];
572 /* Added packages need only look at other added packages. */
573 if (rpmteType(p) == TR_ADDED && rpmteType(otherFi->te) != TR_ADDED)
574 /*@innercontinue@*/ continue;
576 otherFps = otherFi->fps;
577 otherFc = rpmfiFC(otherFi);
579 otherFileNum = findFps(fiFps, otherFps, otherFc);
580 (void) rpmfiSetFX(otherFi, otherFileNum);
582 /* XXX Happens iff fingerprint for incomplete package install. */
583 if (otherFi->actions[otherFileNum] != FA_UNKNOWN)
584 /*@innerbreak@*/ break;
588 switch (rpmteType(p)) {
591 if (otherPkgNum < 0) {
592 /* XXX is this test still necessary? */
593 if (fi->actions[i] != FA_UNKNOWN)
594 /*@switchbreak@*/ break;
595 if ((FFlags & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
596 /* Here is a non-overlapped pre-existing config file. */
597 fi->actions[i] = (FFlags & 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 = rpmfiFSize(otherFi);
620 if ((FFlags & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
621 /* Here is an overlapped pre-existing config file. */
622 fi->actions[i] = (FFlags & 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 (rpmfiFState(fi) != RPMFILE_STATE_NORMAL)
644 /*@switchbreak@*/ break;
645 if (!(S_ISREG(FMode) && (FFlags & 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 = rpmfiMD5(fi);
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, fiFps->entry->dev,
665 rpmfiFSize(fi), 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 = rpmdsNVRMatchesDep(h, req, _rpmds_nopromote);
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) {
892 const char * fdn, * fbn;
895 if (XFA_SKIPPING(fi->actions[i]))
896 /*@innercontinue@*/ continue;
898 fFMode = rpmfiFMode(fi);
900 if (whatis(fFMode) != XDIR)
901 /*@innercontinue@*/ continue;
903 if (strlen(fdn) != dnlen)
904 /*@innercontinue@*/ continue;
905 if (strncmp(fdn, dn, dnlen))
906 /*@innercontinue@*/ continue;
908 if (strlen(fbn) != bnlen)
909 /*@innercontinue@*/ continue;
910 if (strncmp(fbn, bn, bnlen))
911 /*@innercontinue@*/ continue;
912 rpmMessage(RPMMESS_DEBUG, _("excluding directory %s\n"), dn);
913 fi->actions[i] = FA_SKIPNSTATE;
914 /*@innerbreak@*/ break;
918 if (netsharedPaths) freeSplitString(netsharedPaths);
919 #ifdef DYING /* XXX freeFi will deal with this later. */
920 fi->flangs = _free(fi->flangs);
922 if (languages) freeSplitString((char **)languages);
928 * Return transaction element's file info.
929 * @todo Take a rpmfi refcount here.
930 * @param tsi transaction element iterator
931 * @return transaction element file info
934 rpmfi rpmtsiFi(const rpmtsi tsi)
939 if (tsi != NULL && tsi->ocsave != -1) {
940 /*@-type -abstract@*/ /* FIX: rpmte not opaque */
941 rpmte te = rpmtsElement(tsi->ts, tsi->ocsave);
943 if (te != NULL && (fi = te->fi) != NULL)
946 /*@=type =abstract@*/
948 /*@-compdef -refcounttrans -usereleased @*/
950 /*@=compdef =refcounttrans =usereleased @*/
953 #define NOTIFY(_ts, _al) /*@i@*/ if ((_ts)->notify) (void) (_ts)->notify _al
955 int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
959 int totalFileCount = 0;
961 sharedFileInfo shared, sharedList;
965 fingerPrintCache fpc;
967 PSM_t psm = memset(alloca(sizeof(*psm)), 0, sizeof(*psm));
974 /* FIXME: what if the same package is included in ts twice? */
976 if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS)
977 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
978 if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERS)
979 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransTriggers));
981 /* XXX MULTILIB is broken, as packages can and do execute /sbin/ldconfig. */
982 if (rpmtsFlags(ts) & (RPMTRANS_FLAG_JUSTDB | RPMTRANS_FLAG_MULTILIB))
983 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
985 ts->probs = rpmpsFree(ts->probs);
986 ts->probs = rpmpsCreate();
988 /* XXX Make sure the database is open RDWR for package install/erase. */
989 { int dbmode = (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
990 ? O_RDONLY : (O_RDWR|O_CREAT);
992 /* Open database RDWR for installing packages. */
993 if (rpmtsOpenDB(ts, dbmode))
994 return -1; /* XXX W2DO? */
997 ts->ignoreSet = ignoreSet;
998 { const char * currDir = currentDirectory();
999 rpmtsSetCurrDir(ts, currDir);
1000 currDir = _free(currDir);
1003 (void) rpmtsSetChrootDone(ts, 0);
1005 { int_32 tid = (int_32) time(NULL);
1006 (void) rpmtsSetTid(ts, tid);
1009 memset(psm, 0, sizeof(*psm));
1010 psm->ts = rpmtsLink(ts, "tsRun");
1012 /* Get available space on mounted file systems. */
1013 xx = rpmtsInitDSI(ts);
1015 /* ===============================================
1016 * For packages being installed:
1017 * - verify package arch/os.
1018 * - verify package epoch:version-release is newer.
1020 * For packages being removed:
1024 rpmMessage(RPMMESS_DEBUG, _("sanity checking %d elments\n"), rpmtsNElements(ts));
1025 ps = rpmtsProblems(ts);
1026 /* The ordering doesn't matter here */
1027 pi = rpmtsiInit(ts);
1028 while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) {
1029 rpmdbMatchIterator mi;
1032 if ((fi = rpmtsiFi(pi)) == NULL)
1033 continue; /* XXX can't happen */
1036 if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREARCH))
1037 if (!archOkay(rpmteA(p)))
1038 rpmpsAppend(ps, RPMPROB_BADARCH,
1039 rpmteNEVR(p), rpmteKey(p),
1043 if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_IGNOREOS))
1044 if (!osOkay(rpmteO(p)))
1045 rpmpsAppend(ps, RPMPROB_BADOS,
1046 rpmteNEVR(p), rpmteKey(p),
1050 if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_OLDPACKAGE)) {
1052 mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0);
1053 while ((h = rpmdbNextIterator(mi)) != NULL)
1054 xx = ensureOlder(ts, p, h);
1055 mi = rpmdbFreeIterator(mi);
1058 /* XXX multilib should not display "already installed" problems */
1059 if (!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEPKG) && !rpmteMultiLib(p)) {
1060 mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0);
1061 xx = rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_DEFAULT,
1063 xx = rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_DEFAULT,
1066 while (rpmdbNextIterator(mi) != NULL) {
1067 rpmpsAppend(ps, RPMPROB_PKG_INSTALLED,
1068 rpmteNEVR(p), rpmteKey(p),
1071 /*@innerbreak@*/ break;
1073 mi = rpmdbFreeIterator(mi);
1076 /* Count no. of files (if any). */
1077 totalFileCount += fc;
1080 pi = rpmtsiFree(pi);
1083 /* The ordering doesn't matter here */
1084 pi = rpmtsiInit(ts);
1085 while ((p = rpmtsiNext(pi, TR_REMOVED)) != NULL) {
1088 if ((fi = rpmtsiFi(pi)) == NULL)
1089 continue; /* XXX can't happen */
1092 totalFileCount += fc;
1094 pi = rpmtsiFree(pi);
1096 /* ===============================================
1097 * Initialize transaction element file info for package:
1101 * FIXME?: we'd be better off assembling one very large file list and
1102 * calling fpLookupList only once. I'm not sure that the speedup is
1103 * worth the trouble though.
1105 rpmMessage(RPMMESS_DEBUG, _("computing %d file fingerprints\n"), totalFileCount);
1106 numAdded = numRemoved = 0;
1107 pi = rpmtsiInit(ts);
1108 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1111 if ((fi = rpmtsiFi(pi)) == NULL)
1112 continue; /* XXX can't happen */
1116 switch (rpmteType(p)) {
1120 /* Skip netshared paths, not our i18n files, and excluded docs */
1123 /*@switchbreak@*/ break;
1126 fi->record = rpmteDBOffset(p);
1127 /*@switchbreak@*/ break;
1131 fi->fps = (fc > 0 ? xmalloc(fc * sizeof(*fi->fps)) : NULL);
1133 pi = rpmtsiFree(pi);
1135 if (!rpmtsChrootDone(ts)) {
1136 const char * rootDir = rpmtsRootDir(ts);
1138 /*@-superuser -noeffect @*/
1139 if (rootDir != NULL)
1140 xx = chroot(rootDir);
1141 /*@=superuser =noeffect @*/
1142 (void) rpmtsSetChrootDone(ts, 1);
1145 ts->ht = htCreate(totalFileCount * 2, 0, 0, fpHashFunction, fpEqual);
1146 fpc = fpCacheCreate(totalFileCount);
1148 /* ===============================================
1149 * Add fingerprint for each file not skipped.
1151 pi = rpmtsiInit(ts);
1152 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1155 if ((fi = rpmtsiFi(pi)) == NULL)
1156 continue; /* XXX can't happen */
1159 fpLookupList(fpc, fi->dnl, fi->bnl, fi->dil, fc, fi->fps);
1161 fi = rpmfiInit(fi, 0);
1162 if (fi != NULL) /* XXX lclint */
1163 while ((i = rpmfiNext(fi)) >= 0) {
1164 if (XFA_SKIPPING(fi->actions[i]))
1165 /*@innercontinue@*/ continue;
1166 /*@-dependenttrans@*/
1167 htAddEntry(ts->ht, fi->fps + i, (void *) fi);
1168 /*@=dependenttrans@*/
1172 pi = rpmtsiFree(pi);
1174 NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_START, 6, ts->orderCount,
1175 NULL, ts->notifyData));
1177 /* ===============================================
1178 * Compute file disposition for each package in transaction set.
1180 rpmMessage(RPMMESS_DEBUG, _("computing file dispositions\n"));
1181 ps = rpmtsProblems(ts);
1182 pi = rpmtsiInit(ts);
1183 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1184 dbiIndexSet * matches;
1188 if ((fi = rpmtsiFi(pi)) == NULL)
1189 continue; /* XXX can't happen */
1192 NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_PROGRESS, rpmtsiOc(pi),
1193 ts->orderCount, NULL, ts->notifyData));
1195 if (fc == 0) continue;
1197 /* Extract file info for all files in this package from the database. */
1198 matches = xcalloc(fc, sizeof(*matches));
1199 if (rpmdbFindFpList(rpmtsGetRdb(ts), fi->fps, matches, fc)) {
1200 psm->ts = rpmtsUnlink(ts, "tsRun (rpmFindFpList fail)");
1202 return 1; /* XXX WTFO? */
1206 fi = rpmfiInit(fi, 0);
1207 while ((i = rpmfiNext(fi)) >= 0)
1208 numShared += dbiIndexSetCount(matches[i]);
1210 /* Build sorted file info list for this package. */
1211 shared = sharedList = xcalloc((numShared + 1), sizeof(*sharedList));
1213 fi = rpmfiInit(fi, 0);
1214 while ((i = rpmfiNext(fi)) >= 0) {
1216 * Take care not to mark files as replaced in packages that will
1217 * have been removed before we will get here.
1219 for (j = 0; j < dbiIndexSetCount(matches[i]); j++) {
1221 ro = dbiIndexRecordOffset(matches[i], j);
1223 qi = rpmtsiInit(ts);
1224 while ((q = rpmtsiNext(qi, TR_REMOVED)) != NULL) {
1226 /*@innerbreak@*/ break;
1227 if (rpmteDBOffset(q) == ro)
1230 qi = rpmtsiFree(qi);
1232 shared->pkgFileNum = i;
1233 shared->otherPkg = dbiIndexRecordOffset(matches[i], j);
1234 shared->otherFileNum = dbiIndexRecordFileNumber(matches[i], j);
1235 shared->isRemoved = (knownBad == ro);
1238 matches[i] = dbiFreeIndexSet(matches[i]);
1240 numShared = shared - sharedList;
1241 shared->otherPkg = -1;
1242 matches = _free(matches);
1244 /* Sort file info by other package index (otherPkg) */
1245 qsort(sharedList, numShared, sizeof(*shared), sharedCmp);
1247 /* For all files from this package that are in the database ... */
1249 for (i = 0; i < numShared; i = nexti) {
1252 shared = sharedList + i;
1254 /* Find the end of the files in the other package. */
1255 for (nexti = i + 1; nexti < numShared; nexti++) {
1256 if (sharedList[nexti].otherPkg != shared->otherPkg)
1257 /*@innerbreak@*/ break;
1260 /* Is this file from a package being removed? */
1262 if (ts->removedPackages != NULL)
1263 for (j = 0; j < ts->numRemovedPackages; j++) {
1264 if (ts->removedPackages[j] != shared->otherPkg)
1265 /*@innercontinue@*/ continue;
1267 /*@innerbreak@*/ break;
1270 /* Determine the fate of each file. */
1271 switch (rpmteType(p)) {
1273 xx = handleInstInstalledFiles(ts, p, fi, shared, nexti - i,
1274 !(beingRemoved || (rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEOLDFILES)));
1275 /*@switchbreak@*/ break;
1278 xx = handleRmvdInstalledFiles(ts, fi, shared, nexti - i);
1279 /*@switchbreak@*/ break;
1286 /* Update disk space needs on each partition for this package. */
1287 handleOverlappedFiles(ts, p, fi);
1289 /* Check added package has sufficient space on each partition used. */
1290 switch (rpmteType(p)) {
1292 rpmtsCheckDSIProblems(ts, p);
1293 /*@switchbreak@*/ break;
1295 /*@switchbreak@*/ break;
1298 pi = rpmtsiFree(pi);
1301 if (rpmtsChrootDone(ts)) {
1302 const char * currDir = rpmtsCurrDir(ts);
1303 /*@-superuser -noeffect @*/
1305 /*@=superuser =noeffect @*/
1306 (void) rpmtsSetChrootDone(ts, 0);
1307 if (currDir != NULL)
1308 xx = chdir(currDir);
1311 NOTIFY(ts, (NULL, RPMCALLBACK_TRANS_STOP, 6, ts->orderCount,
1312 NULL, ts->notifyData));
1314 /* ===============================================
1315 * Free unused memory as soon as possible.
1317 pi = rpmtsiInit(ts);
1318 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1319 if ((fi = rpmtsiFi(pi)) == NULL)
1320 continue; /* XXX can't happen */
1321 if (rpmfiFC(fi) == 0)
1323 fi->fps = _free(fi->fps);
1325 pi = rpmtsiFree(pi);
1327 fpc = fpCacheFree(fpc);
1328 ts->ht = htFree(ts->ht);
1330 /* ===============================================
1331 * If unfiltered problems exist, free memory and return.
1333 if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS)
1334 || (ts->probs->numProblems &&
1335 (okProbs != NULL || rpmpsTrim(ts->probs, okProbs)))
1338 if (psm->ts != NULL)
1339 psm->ts = rpmtsUnlink(psm->ts, "tsRun (problems)");
1340 return ts->orderCount;
1343 /* ===============================================
1344 * Save removed files before erasing.
1346 if (rpmtsFlags(ts) & (RPMTRANS_FLAG_DIRSTASH | RPMTRANS_FLAG_REPACKAGE)) {
1349 pi = rpmtsiInit(ts);
1350 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1352 switch (rpmteType(p)) {
1354 /*@switchbreak@*/ break;
1356 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_REPACKAGE))
1357 /*@switchbreak@*/ break;
1359 NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_START,
1360 7, numRemoved, NULL, ts->notifyData));
1362 NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_PROGRESS, progress,
1363 numRemoved, NULL, ts->notifyData));
1367 psm->fi = rpmfiLink(fi, "tsRepackage");
1368 /* XXX TR_REMOVED needs CPIO_MAP_{ABSOLUTE,ADDDOT} CPIO_ALL_HARDLINKS */
1369 psm->fi->mapflags |= CPIO_MAP_ABSOLUTE;
1370 psm->fi->mapflags |= CPIO_MAP_ADDDOT;
1371 psm->fi->mapflags |= CPIO_ALL_HARDLINKS;
1372 xx = psmStage(psm, PSM_PKGSAVE);
1373 (void) rpmfiUnlink(fi, "tsRepackage");
1376 /*@switchbreak@*/ break;
1379 pi = rpmtsiFree(pi);
1381 NOTIFY(ts, (NULL, RPMCALLBACK_REPACKAGE_STOP, 7, numRemoved,
1382 NULL, ts->notifyData));
1386 /* ===============================================
1387 * Install and remove packages.
1389 rpmMessage(RPMMESS_DEBUG, _("install/erase %d elements\n"), rpmtsNElements(ts));
1390 lastKey = (alKey)-2; /* erased packages have -1 */
1391 pi = rpmtsiInit(ts);
1392 /*@-branchstate@*/ /* FIX: fi reload needs work */
1393 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1398 if ((fi = rpmtsiFi(pi)) == NULL)
1399 continue; /* XXX can't happen */
1402 psm->fi = rpmfiLink(fi, "tsInstall");
1403 switch (rpmteType(p)) {
1406 pkgKey = rpmteAddedKey(p);
1408 rpmMessage(RPMMESS_DEBUG, "========== +++ %s\n", rpmteNEVR(p));
1410 /*@-type@*/ /* FIX: rpmte not opaque */
1412 /*@-noeffectuncon@*/ /* FIX: notify annotations */
1413 p->fd = ts->notify(fi->h, RPMCALLBACK_INST_OPEN_FILE, 0, 0,
1414 rpmteKey(p), ts->notifyData);
1415 /*@=noeffectuncon@*/
1416 if (rpmteFd(p) != NULL) {
1417 rpmVSFlags ovsflags = rpmtsVSFlags(ts);
1418 rpmVSFlags vsflags = ovsflags | RPMVSF_NEEDPAYLOAD;
1421 ovsflags = rpmtsSetVSFlags(ts, vsflags);
1422 rpmrc = rpmReadPackageFile(ts, rpmteFd(p),
1423 rpmteNEVR(p), &p->h);
1424 vsflags = rpmtsSetVSFlags(ts, ovsflags);
1426 if (!(rpmrc == RPMRC_OK || rpmrc == RPMRC_BADSIZE)) {
1427 /*@-noeffectuncon@*/ /* FIX: notify annotations */
1428 p->fd = ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE,
1430 rpmteKey(p), ts->notifyData);
1431 /*@=noeffectuncon@*/
1435 if (rpmteFd(p) != NULL) gotfd = 1;
1440 if (rpmteFd(p) != NULL) {
1442 char * fstates = fi->fstates;
1443 fileAction * actions = fi->actions;
1447 psm->fi = rpmfiFree(psm->fi, 1);
1448 (void) rpmfiFree(fi, 0);
1450 fi->magic = RPMFIMAGIC;
1453 (void) rpmfiNew(ts, fi, p->h, RPMTAG_BASENAMES, 1);
1454 psm->fi = rpmfiLink(fi, "tsInstall");
1455 fi->fstates = _free(fi->fstates);
1456 fi->fstates = fstates;
1457 fi->actions = _free(fi->actions);
1458 fi->actions = actions;
1462 if (rpmteMultiLib(p))
1463 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | RPMTRANS_FLAG_MULTILIB));
1465 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) & ~RPMTRANS_FLAG_MULTILIB));
1467 if (psmStage(psm, PSM_PKGINSTALL)) {
1471 fi->h = headerFree(fi->h);
1477 p->h = headerFree(p->h);
1480 /*@-noeffectuncon @*/ /* FIX: check rc */
1481 (void) ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0,
1482 rpmteKey(p), ts->notifyData);
1483 /*@=noeffectuncon @*/
1488 /*@switchbreak@*/ break;
1490 rpmMessage(RPMMESS_DEBUG, "========== --- %s\n", rpmteNEVR(p));
1491 /* If install failed, then we shouldn't erase. */
1492 if (rpmteDependsOnKey(p) != lastKey) {
1493 if (psmStage(psm, PSM_PKGERASE))
1496 /*@switchbreak@*/ break;
1498 xx = rpmdbSync(rpmtsGetRdb(ts));
1499 (void) rpmfiUnlink(psm->fi, "tsInstall");
1502 /*@-type@*/ /* FIX: p is almost opaque */
1503 p->fi = rpmfiFree(fi, 1);
1507 pi = rpmtsiFree(pi);
1509 psm->ts = rpmtsUnlink(psm->ts, "tsRun");
1511 /*@-nullstate@*/ /* FIX: ts->flList may be NULL */