2 * \file lib/transaction.c
10 #include <rpm/rpmlib.h> /* rpmMachineScore, rpmReadPackageFile */
11 #include <rpm/rpmmacro.h> /* XXX for rpmExpand */
12 #include <rpm/rpmlog.h>
13 #include <rpm/rpmdb.h>
14 #include <rpm/rpmds.h>
15 #include <rpm/rpmfileutil.h>
16 #include <rpm/rpmstring.h>
17 #include <rpm/rpmsq.h>
19 #include "lib/fprint.h"
21 #include "lib/rpmchroot.h"
22 #include "lib/rpmlock.h"
23 #include "lib/rpmds_internal.h"
24 #include "lib/rpmfi_internal.h" /* only internal apis */
25 #include "lib/rpmte_internal.h" /* only internal apis */
26 #include "lib/rpmts_internal.h"
27 #include "rpmio/rpmhook.h"
28 #include "lib/rpmtriggers.h"
30 #include "lib/rpmplugins.h"
32 /* XXX FIXME: merge with existing (broken?) tests in system.h */
33 /* portability fiddles */
34 #if STATFS_IN_SYS_STATVFS
35 #include <sys/statvfs.h>
38 # if STATFS_IN_SYS_VFS
41 # if STATFS_IN_SYS_MOUNT
42 # include <sys/mount.h>
44 # if STATFS_IN_SYS_STATFS
45 # include <sys/statfs.h>
53 struct diskspaceInfo_s {
54 char * mntPoint; /*!< File system mount point */
55 dev_t dev; /*!< File system device number. */
56 int64_t bneeded; /*!< No. of blocks needed. */
57 int64_t ineeded; /*!< No. of inodes needed. */
58 int64_t bsize; /*!< File system block size. */
59 int64_t bavail; /*!< No. of blocks available. */
60 int64_t iavail; /*!< No. of inodes available. */
61 int64_t obneeded; /*!< Bookkeeping to avoid duplicate reports */
62 int64_t oineeded; /*!< Bookkeeping to avoid duplicate reports */
63 int64_t bdelta; /*!< Delta for temporary space need on updates */
64 int64_t idelta; /*!< Delta for temporary inode need on updates */
67 /* Adjust for root only reserved space. On linux e2fs, this is 5%. */
68 #define adj_fs_blocks(_nb) (((_nb) * 21) / 20)
69 #define BLOCK_ROUND(size, block) (((size) + (block) - 1) / (block))
71 static char *getMntPoint(const char *dirName, dev_t dev)
73 char mntPoint[PATH_MAX];
74 char *resolved_path = realpath(dirName, mntPoint);
80 strncpy(mntPoint, dirName, PATH_MAX);
81 mntPoint[PATH_MAX-1] = '\0';
84 while (end != mntPoint) {
85 end = strrchr(mntPoint, '/');
86 if (end == mntPoint) { /* reached "/" */
88 if (dev != sb.st_dev) {
89 res = xstrdup(mntPoint);
96 } else { /* dirName doesn't start with / - should not happen */
97 res = xstrdup(dirName);
101 if (dev != sb.st_dev) {
103 res = xstrdup(mntPoint);
110 static int rpmtsInitDSI(const rpmts ts)
112 if (rpmtsFilterFlags(ts) & RPMPROB_FILTER_DISKSPACE)
114 ts->dsi = _free(ts->dsi);
115 ts->dsi = xcalloc(1, sizeof(*ts->dsi));
119 static rpmDiskSpaceInfo rpmtsCreateDSI(const rpmts ts, dev_t dev,
120 const char * dirName, int count)
122 rpmDiskSpaceInfo dsi;
126 #if STATFS_IN_SYS_STATVFS
128 memset(&sfb, 0, sizeof(sfb));
129 rc = statvfs(dirName, &sfb);
132 memset(&sfb, 0, sizeof(sfb));
134 /* This platform has the 4-argument version of the statfs call. The last two
135 * should be the size of struct statfs and 0, respectively. The 0 is the
136 * filesystem type, and is always 0 when statfs is called on a mounted
137 * filesystem, as we're doing.
139 rc = statfs(dirName, &sfb, sizeof(sfb), 0);
141 rc = statfs(dirName, &sfb);
147 rc = stat(dirName, &sb);
150 if (sb.st_dev != dev)
153 ts->dsi = xrealloc(ts->dsi, (count + 2) * sizeof(*ts->dsi));
154 dsi = ts->dsi + count;
155 memset(dsi, 0, 2 * sizeof(*dsi));
157 dsi->dev = sb.st_dev;
158 dsi->bsize = sfb.f_bsize;
160 dsi->bsize = 512; /* we need a bsize */
163 #ifdef STATFS_HAS_F_BAVAIL
164 dsi->bavail = (sfb.f_flag & ST_RDONLY) ? 0 : sfb.f_bavail;
166 /* FIXME: the statfs struct doesn't have a member to tell how many blocks are
167 * available for non-superusers. f_blocks - f_bfree is probably too big, but
168 * it's about all we can do.
170 dsi->bavail = sfb.f_blocks - sfb.f_bfree;
172 /* XXX Avoid FAT and other file systems that have not inodes. */
173 /* XXX assigning negative value to unsigned type */
174 dsi->iavail = !(sfb.f_ffree == 0 && sfb.f_files == 0)
177 /* Find mount point belonging to this device number */
178 dsi->mntPoint = getMntPoint(dirName, dsi->dev);
180 /* normalize block size to 4096 bytes if it is too big. */
181 if (dsi->bsize > 4096) {
182 uint64_t old_size = dsi->bavail * dsi->bsize;
184 "dubious blocksize % " PRId64 " on %s, normalizing to 4096\n",
185 dsi->bsize, dsi->mntPoint);
186 dsi->bsize = 4096; /* Assume 4k block size */
187 dsi->bavail = old_size / dsi->bsize;
191 "0x%08x %8" PRId64 " %12" PRId64 " %12" PRId64" %s\n",
192 (unsigned) dsi->dev, dsi->bsize,
193 dsi->bavail, dsi->iavail,
198 static rpmDiskSpaceInfo rpmtsGetDSI(const rpmts ts, dev_t dev,
199 const char *dirName) {
200 rpmDiskSpaceInfo dsi;
203 while (dsi->bsize && dsi->dev != dev)
205 if (dsi->bsize == 0) {
206 /* create new entry */
207 dsi = rpmtsCreateDSI(ts, dev, dirName, dsi - ts->dsi);
213 static void rpmtsUpdateDSI(const rpmts ts, dev_t dev, const char *dirName,
214 rpm_loff_t fileSize, rpm_loff_t prevSize, rpm_loff_t fixupSize,
215 rpmFileAction action)
218 rpmDiskSpaceInfo dsi = rpmtsGetDSI(ts, dev, dirName);
222 bneeded = BLOCK_ROUND(fileSize, dsi->bsize);
229 dsi->bneeded += bneeded;
233 dsi->bneeded += bneeded;
236 dsi->bdelta += BLOCK_ROUND(prevSize, dsi->bsize);
240 dsi->bdelta += BLOCK_ROUND(fixupSize, dsi->bsize);
248 dsi->bneeded -= bneeded;
255 /* adjust bookkeeping when requirements shrink */
256 if (dsi->bneeded < dsi->obneeded) dsi->obneeded = dsi->bneeded;
257 if (dsi->ineeded < dsi->oineeded) dsi->oineeded = dsi->ineeded;
260 static void rpmtsCheckDSIProblems(const rpmts ts, const rpmte te)
262 rpmDiskSpaceInfo dsi = ts->dsi;
264 if (dsi == NULL || !dsi->bsize)
267 for (; dsi->bsize; dsi++) {
269 if (dsi->bavail >= 0 && adj_fs_blocks(dsi->bneeded) > dsi->bavail) {
270 if (dsi->bneeded > dsi->obneeded) {
271 rpmteAddProblem(te, RPMPROB_DISKSPACE, NULL, dsi->mntPoint,
272 (adj_fs_blocks(dsi->bneeded) - dsi->bavail) * dsi->bsize);
273 dsi->obneeded = dsi->bneeded;
277 if (dsi->iavail >= 0 && adj_fs_blocks(dsi->ineeded) > dsi->iavail) {
278 if (dsi->ineeded > dsi->oineeded) {
279 rpmteAddProblem(te, RPMPROB_DISKNODES, NULL, dsi->mntPoint,
280 (adj_fs_blocks(dsi->ineeded) - dsi->iavail));
281 dsi->oineeded = dsi->ineeded;
285 /* Adjust for temporary -> final disk consumption */
286 dsi->bneeded -= dsi->bdelta;
288 dsi->ineeded -= dsi->idelta;
293 static void rpmtsFreeDSI(rpmts ts)
295 rpmDiskSpaceInfo dsi;
299 while (dsi && dsi->bsize != 0) {
300 dsi->mntPoint = _free(dsi->mntPoint);
304 ts->dsi = _free(ts->dsi);
308 /* Calculate total number of files involved in transaction */
309 static uint64_t countFiles(rpmts ts)
312 rpmtsi pi = rpmtsiInit(ts);
315 while ((p = rpmtsiNext(pi, 0)) != NULL) {
316 files = rpmteFiles(p);
317 fc += rpmfilesFC(files);
324 static int handleRemovalConflict(rpmfiles fi, int fx, rpmfiles ofi, int ofx)
326 int rConflicts = 0; /* Removed files don't conflict, normally */
327 rpmFileTypes ft = rpmfiWhatis(rpmfilesFMode(fi, fx));
328 rpmFileTypes oft = rpmfiWhatis(rpmfilesFMode(ofi, ofx));
333 /* We can't handle directory changing to anything else */
336 } else if (oft == LINK) {
337 /* We can't correctly handle directory symlink changing to directory */
339 fn = rpmfilesFN(fi, fx);
340 if (stat(fn, &sb) == 0 && S_ISDIR(sb.st_mode))
346 * ...but if the conflicting item is either not on disk, or has
347 * already been changed to the new type, we should be ok afterall.
351 fn = rpmfilesFN(fi, fx);
352 if (lstat(fn, &sb) || rpmfiWhatis(sb.st_mode) == ft)
361 * Elf files can be "colored", and if enabled in the transaction, the
362 * color can be used to resolve conflicts between elf-64bit and elf-32bit
363 * files to the hosts preferred type, by default 64bit. The non-preferred
364 * type is overwritten or never installed at all and thus the conflict
365 * magically disappears. This is infamously nasty "rpm magic" and entirely
366 * unnecessary with careful packaging.
368 static int handleColorConflict(rpmts ts,
369 rpmfs fs, rpmfiles fi, int fx,
370 rpmfs ofs, rpmfiles ofi, int ofx)
373 rpm_color_t tscolor = rpmtsColor(ts);
376 rpm_color_t fcolor = rpmfilesFColor(fi, fx) & tscolor;
377 rpm_color_t ofcolor = rpmfilesFColor(ofi, ofx) & tscolor;
379 if (fcolor != 0 && ofcolor != 0 && fcolor != ofcolor) {
380 rpm_color_t prefcolor = rpmtsPrefColor(ts);
382 if (fcolor & prefcolor) {
383 if (ofs && !XFA_SKIPPING(rpmfsGetAction(fs, fx)))
384 rpmfsSetAction(ofs, ofx, FA_SKIPCOLOR);
385 rpmfsSetAction(fs, fx, FA_CREATE);
387 } else if (ofcolor & prefcolor) {
388 if (ofs && XFA_SKIPPING(rpmfsGetAction(fs, fx)))
389 rpmfsSetAction(ofs, ofx, FA_CREATE);
390 rpmfsSetAction(fs, fx, FA_SKIPCOLOR);
400 * handleInstInstalledFiles.
401 * @param ts transaction set
402 * @param p current transaction element
403 * @param fi file info set
404 * @param fx file index
405 * @param otherHeader header containing the matching file
406 * @param otherFi matching file info set
407 * @param ofx matching file index
408 * @param beingRemoved file being removed (installed otherwise)
410 /* XXX only ts->{probs,rpmdb} modified */
411 static void handleInstInstalledFile(const rpmts ts, rpmte p, rpmfiles fi, int fx,
412 Header otherHeader, rpmfiles otherFi, int ofx,
415 rpmfs fs = rpmteGetFileStates(p);
416 int isCfgFile = ((rpmfilesFFlags(otherFi, ofx) | rpmfilesFFlags(fi, fx)) & RPMFILE_CONFIG);
418 if (XFA_SKIPPING(rpmfsGetAction(fs, fx)))
421 if (rpmfilesCompare(otherFi, ofx, fi, fx)) {
423 char rState = RPMFILE_STATE_REPLACED;
426 * There are some removal conflicts we can't handle. However
427 * if the package has a %pretrans scriptlet, it might be able to
428 * fix the conflict. Let it through on test-transaction to allow
429 * eg yum to get past it, if the conflict is present on the actual
430 * transaction we'll abort. Behaving differently on test is nasty,
431 * but its still better than barfing in middle of large transaction.
434 rConflicts = handleRemovalConflict(fi, fx, otherFi, ofx);
435 if (rConflicts && rpmteHaveTransScript(p, RPMTAG_PRETRANS)) {
436 if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
442 /* If enabled, resolve colored conflicts to preferred type */
443 rConflicts = handleColorConflict(ts, fs, fi, fx,
445 /* If resolved, we need to adjust in-rpmdb state too */
446 if (rConflicts == 0 && rpmfsGetAction(fs, fx) == FA_CREATE)
447 rState = RPMFILE_STATE_WRONGCOLOR;
452 char *path = rpmfilesFN(fi, fx);
453 /* Call file conflict hook for all plugins */
454 rpmpluginsCallFileConflict(ts->plugins, ts, path, otherHeader, otherFi, rConflicts);
457 /* Somebody used The Force, lets shut up... */
458 if (rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEOLDFILES) {
464 char *altNEVR = headerGetAsString(otherHeader, RPMTAG_NEVRA);
465 char *fn = rpmfilesFN(fi, fx);
466 rpmteAddProblem(p, RPMPROB_FILE_CONFLICT, altNEVR, fn,
467 headerGetInstance(otherHeader));
472 /* Save file identifier to mark as state REPLACED. */
473 if ( !(isCfgFile || XFA_SKIPPING(rpmfsGetAction(fs, fx))) ) {
475 rpmfsAddReplaced(rpmteGetFileStates(p), fx, rState,
476 headerGetInstance(otherHeader), ofx);
480 /* Determine config file disposition, skipping missing files (if any). */
482 int skipMissing = ((rpmtsFlags(ts) & RPMTRANS_FLAG_ALLFILES) ? 0 : 1);
483 rpmFileAction action;
484 action = rpmfilesDecideFate(otherFi, ofx, fi, fx, skipMissing);
485 rpmfsSetAction(fs, fx, action);
488 /* Skip already existing files - if 'minimize_writes' is set. */
489 if ((!isCfgFile) && (rpmfsGetAction(fs, fx) == FA_UNKNOWN) && ts->min_writes) {
490 if (rpmfileContentsEqual(otherFi, ofx, fi, fx)) {
491 rpmfsSetAction(fs, fx, FA_TOUCH);
495 rpmfilesSetFReplacedSize(fi, fx, rpmfilesFSize(otherFi, ofx));
499 * Update disk space needs on each partition for this package's files.
501 /* XXX only ts->{probs,di} modified */
502 static void handleOverlappedFiles(rpmts ts, fingerPrintCache fpc, rpmte p, rpmfiles fi)
504 rpm_loff_t fixupSize = 0;
506 rpmfs fs = rpmteGetFileStates(p);
508 rpm_count_t fc = rpmfilesFC(fi);
509 int reportConflicts = !(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACENEWFILES);
510 fingerPrint * fpList = rpmfilesFps(fi);
512 for (i = 0; i < fc; i++) {
513 struct fingerPrint_s * fiFps;
514 int otherPkgNum, otherFileNum;
518 struct rpmffi_s * recs;
521 if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
524 FFlags = rpmfilesFFlags(fi, 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 fiFps = fpCacheGetByFp(fpc, fpList, i, &recs, &numRecs);
537 * If this package is being added, look only at other packages
538 * being added -- removed packages dance to a different tune.
540 * If both this and the other package are being added, overlapped
541 * files must be identical (or marked as a conflict). The
542 * disposition of already installed config files leads to
543 * a small amount of extra complexity.
545 * If this package is being removed, then there are two cases that
546 * need to be worried about:
547 * If the other package is being added, then skip any overlapped files
548 * so that this package removal doesn't nuke the overlapped files
549 * that were just installed.
550 * If both this and the other package are being removed, then each
551 * file removal from preceding packages needs to be skipped so that
552 * the file removal occurs only on the last occurrence of an overlapped
553 * file in the transaction set.
558 * Locate this overlapped file in the set of added/removed packages,
559 * including the package owning it: a package can have self-conflicting
560 * files when directory symlinks are present. Don't compare a file
561 * with itself though...
563 for (j = 0; j < numRecs && !(recs[j].p == p && recs[j].fileno == i); j++)
566 /* Find what the previous disposition of this file was. */
567 otherFileNum = -1; /* keep gcc quiet */
572 for (otherPkgNum = j - 1; otherPkgNum >= 0; otherPkgNum--) {
573 otherTe = recs[otherPkgNum].p;
574 otherFileNum = recs[otherPkgNum].fileno;
575 otherFs = rpmteGetFileStates(otherTe);
577 /* Added packages need only look at other added packages. */
578 if (rpmteType(p) == TR_ADDED && rpmteType(otherTe) != TR_ADDED)
581 /* XXX Happens iff fingerprint for incomplete package install. */
582 if (rpmfsGetAction(otherFs, otherFileNum) != FA_UNKNOWN) {
583 otherFi = rpmteFiles(otherTe);
588 switch (rpmteType(p)) {
590 if (otherPkgNum < 0) {
591 /* XXX is this test still necessary? */
592 rpmFileAction action;
593 if (rpmfsGetAction(fs, i) != FA_UNKNOWN)
595 if (rpmfilesConfigConflict(fi, i)) {
596 /* Here is a non-overlapped pre-existing config file. */
597 action = (FFlags & RPMFILE_NOREPLACE) ?
598 FA_ALTNAME : FA_BACKUP;
602 rpmfsSetAction(fs, i, action);
606 assert(otherFi != NULL);
607 /* Mark added overlapped non-identical files as a conflict. */
608 if (rpmfilesCompare(otherFi, otherFileNum, fi, i)) {
611 /* If enabled, resolve colored conflicts to preferred type */
612 rConflicts = handleColorConflict(ts, fs, fi, i,
613 otherFs, otherFi, otherFileNum);
615 if (rConflicts && reportConflicts) {
616 char *fn = rpmfilesFN(fi, i);
617 rpmteAddProblem(p, RPMPROB_NEW_FILE_CONFLICT,
618 rpmteNEVRA(otherTe), fn, 0);
622 /* Skip create on all but the first instance of a shared file */
623 rpmFileAction oaction = rpmfsGetAction(otherFs, otherFileNum);
624 if (oaction != FA_UNKNOWN && !XFA_SKIPPING(oaction)) {
626 /* ...but ghosts aren't really created so... */
627 oflags = rpmfilesFFlags(otherFi, otherFileNum);
628 if (!(oflags & RPMFILE_GHOST)) {
629 rpmfsSetAction(fs, i, FA_SKIP);
631 /* if the other file is color skipped then skip this file too */
632 } else if (oaction == FA_SKIPCOLOR) {
633 rpmfsSetAction(fs, i, FA_SKIPCOLOR);
637 /* Skipped files dont need fixup size or backups, %config or not */
638 if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
641 /* Try to get the disk accounting correct even if a conflict. */
642 fixupSize = rpmfilesFSize(otherFi, otherFileNum);
644 if (rpmfilesConfigConflict(fi, i)) {
645 /* Here is an overlapped pre-existing config file. */
646 rpmFileAction action;
647 action = (FFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SKIP;
648 rpmfsSetAction(fs, i, action);
650 /* If not decided yet, create it */
651 if (rpmfsGetAction(fs, i) == FA_UNKNOWN)
652 rpmfsSetAction(fs, i, FA_CREATE);
657 if (otherPkgNum >= 0) {
658 assert(otherFi != NULL);
659 /* Here is an overlapped added file we don't want to nuke. */
660 if (rpmfsGetAction(otherFs, otherFileNum) != FA_ERASE) {
661 /* On updates, don't remove files. */
662 rpmfsSetAction(fs, i, FA_SKIP);
665 /* Here is an overlapped removed file: skip in previous. */
666 rpmfsSetAction(otherFs, otherFileNum, FA_SKIP);
668 if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
670 if (rpmfilesFState(fi, i) != RPMFILE_STATE_NORMAL) {
671 rpmfsSetAction(fs, i, FA_SKIP);
675 /* Pre-existing modified config files need to be saved. */
676 if (rpmfilesConfigConflict(fi, i)) {
677 rpmfsSetAction(fs, i, FA_SAVE);
681 /* Otherwise, we can just erase. */
682 rpmfsSetAction(fs, i, FA_ERASE);
685 rpmfilesFree(otherFi);
687 /* Update disk space info for a file. */
688 rpmtsUpdateDSI(ts, fpEntryDev(fpc, fiFps), fpEntryDir(fpc, fiFps),
689 rpmfilesFSize(fi, i), rpmfilesFReplacedSize(fi, i),
690 fixupSize, rpmfsGetAction(fs, i));
696 * Ensure that current package is newer than installed package.
697 * @param tspool transaction string pool
698 * @param p current transaction element
699 * @param h installed header
701 static void ensureOlder(rpmstrPool tspool, const rpmte p, const Header h)
703 rpmsenseFlags reqFlags = (RPMSENSE_LESS | RPMSENSE_EQUAL);
706 req = rpmdsSinglePool(tspool, RPMTAG_REQUIRENAME,
707 rpmteN(p), rpmteEVR(p), reqFlags);
708 if (rpmdsMatches(tspool, h, -1, req, 1, _rpmds_nopromote) == 0) {
709 char * altNEVR = headerGetAsString(h, RPMTAG_NEVRA);
710 rpmteAddProblem(p, RPMPROB_OLDPACKAGE, altNEVR, NULL,
711 headerGetInstance(h));
718 * Check if the curent file in the file iterator is in the
719 * netshardpath and though should be excluded.
720 * @param ts transaction set
721 * @param fi file info set
722 * @returns 1 if path is net shared path, otherwise 0
724 static int matchNetsharedpath(const rpmts ts, rpmfi fi)
727 const char * dn, * bn;
734 for (nsp = ts->netsharedPaths; nsp && *nsp; nsp++) {
739 if (!rstreqn(dn, *nsp, len))
741 /* Only directories or complete file paths can be net shared */
742 if (!(dn[len] == '/' || dn[len] == '\0'))
745 if (len < (dnlen + bnlen))
747 if (!rstreqn(dn, *nsp, dnlen))
749 /* Insure that only the netsharedpath basename is compared. */
750 if ((s = strchr((*nsp) + dnlen, '/')) != NULL && s[1] != '\0')
752 if (!rstreqn(bn, (*nsp) + dnlen, bnlen))
755 /* Only directories or complete file paths can be net shared */
756 if (!((*nsp)[len] == '/' || (*nsp)[len] == '\0'))
762 return (nsp != NULL && *nsp != NULL);
765 static void skipEraseFiles(const rpmts ts, rpmfiles files, rpmfs fs)
769 * Skip net shared paths.
770 * Net shared paths are not relative to the current root (though
771 * they do need to take package relocations into account).
773 if (ts->netsharedPaths) {
774 rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD);
775 while ((i = rpmfiNext(fi)) >= 0)
777 if (matchNetsharedpath(ts, fi))
778 rpmfsSetAction(fs, i, FA_SKIPNETSHARED);
786 * Skip any files that do not match install policies.
787 * @param ts transaction set
788 * @param files file info set
789 * @param fs file states
791 static void skipInstallFiles(const rpmts ts, rpmfiles files, rpmfs fs)
793 rpm_color_t tscolor = rpmtsColor(ts);
795 int noConfigs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONFIGS);
796 int noDocs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NODOCS);
801 rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD);
804 noDocs = rpmExpandNumeric("%{_excludedocs}");
806 /* Compute directory refcount, skip directory if now empty. */
808 drc = xcalloc(dc, sizeof(*drc));
809 dff = xcalloc(dc, sizeof(*dff));
811 fi = rpmfiInit(fi, 0);
812 while ((i = rpmfiNext(fi)) >= 0) {
818 /* Don't bother with skipped files */
819 /* XXX FIXME: --excludepath on %license should not be permitted */
820 if (XFA_SKIPPING(rpmfsGetAction(fs, i))) {
821 drc[ix]--; dff[ix] = 1;
825 /* Ignore colored files not in our rainbow. */
826 FColor = rpmfiFColor(fi);
827 if (tscolor && FColor && !(tscolor & FColor)) {
828 drc[ix]--; dff[ix] = 1;
829 rpmfsSetAction(fs, i, FA_SKIPCOLOR);
834 * Skip net shared paths.
835 * Net shared paths are not relative to the current root (though
836 * they do need to take package relocations into account).
838 if (ts->netsharedPaths) {
839 if (matchNetsharedpath(ts, fi)) {
840 drc[ix]--; dff[ix] = 1;
841 rpmfsSetAction(fs, i, FA_SKIPNETSHARED);
847 * In general, excluding license files is not permitted. In case
848 * of SKIPNETSHARED and SKIPCOLOR the file is expected to be
849 * there via other means however so that is ok.
851 if (rpmfiFFlags(fi) & RPMFILE_LICENSE)
855 * Skip i18n language specific files.
857 flangs = (ts->installLangs != NULL) ? rpmfiFLangs(fi) : NULL;
858 if (flangs != NULL && *flangs != '\0') {
861 for (lang = ts->installLangs; *lang != NULL; lang++) {
862 for (l = flangs; *l != '\0'; l = le) {
863 for (le = l; *le != '\0' && *le != '|'; le++)
865 if ((le-l) > 0 && rstreqn(*lang, l, (le-l)))
867 if (*le == '|') le++; /* skip over | */
873 drc[ix]--; dff[ix] = 1;
874 rpmfsSetAction(fs, i, FA_SKIPNSTATE);
880 * Skip config files if requested.
882 if (noConfigs && (rpmfiFFlags(fi) & RPMFILE_CONFIG)) {
883 drc[ix]--; dff[ix] = 1;
884 rpmfsSetAction(fs, i, FA_SKIPNSTATE);
889 * Skip documentation if requested.
891 if (noDocs && (rpmfiFFlags(fi) & RPMFILE_DOC)) {
892 drc[ix]--; dff[ix] = 1;
893 rpmfsSetAction(fs, i, FA_SKIPNSTATE);
898 /* Skip (now empty) directories that had skipped files. */
899 /* Iterate over dirs in reversed order to solve subdirs at first */
900 for (j = dc - 1; j >= 0; j--) {
901 const char * dn, * bn;
904 if (drc[j]) continue; /* dir still has files. */
905 if (!dff[j]) continue; /* dir was not emptied here. */
907 /* Find parent directory and basename. */
908 dn = rpmfilesDN(files, j); dnlen = strlen(dn) - 1;
909 bn = dn + dnlen; bnlen = 0;
910 while (bn > dn && bn[-1] != '/') {
916 /* If explicitly included in the package, skip the directory. */
917 fi = rpmfiInit(fi, 0);
918 while ((i = rpmfiNext(fi)) >= 0) {
919 const char * fdn, * fbn;
922 if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
925 fFMode = rpmfiFMode(fi);
927 if (rpmfiWhatis(fFMode) != XDIR)
930 if (strlen(fdn) != dnlen)
932 if (!rstreqn(fdn, dn, dnlen))
935 if (strlen(fbn) != bnlen)
937 if (!rstreqn(fbn, bn, bnlen))
939 rpmlog(RPMLOG_DEBUG, "excluding directory %s\n", dn);
940 rpmfsSetAction(fs, i, FA_SKIPNSTATE);
942 /* Decrease count of files for parent directory */
944 /* Mark directory because something was removed from them */
959 #define HASHTYPE rpmStringSet
960 #define HTKEYTYPE rpmsid
961 #include "lib/rpmhash.H"
962 #include "lib/rpmhash.C"
964 static unsigned int sidHash(rpmsid sid)
969 static int sidCmp(rpmsid a, rpmsid b)
974 /* Get a rpmdbMatchIterator containing all files in
975 * the rpmdb that share the basename with one from
977 * @param ts transaction set
978 * @return rpmdbMatchIterator sorted
979 by (package, fileNum)
982 rpmdbMatchIterator rpmFindBaseNamesInDB(rpmts ts, uint64_t fileCount)
984 tsMembers tsmem = rpmtsMembers(ts);
985 rpmstrPool tspool = rpmtsPool(ts);
989 rpmdbMatchIterator mi;
991 const char * baseName;
994 rpmStringSet baseNames = rpmStringSetCreate(fileCount,
995 sidHash, sidCmp, NULL);
997 mi = rpmdbNewIterator(rpmtsGetRdb(ts), RPMDBI_BASENAMES);
1000 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1003 rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_PROGRESS, oc++, tsmem->orderCount);
1005 /* Gather all installed headers with matching basename's. */
1006 files = rpmteFiles(p);
1007 fi = rpmfilesIter(files, RPMFI_ITER_FWD);
1008 while (rpmfiNext(fi) >= 0) {
1011 baseNameId = rpmfiBNId(fi);
1013 if (rpmStringSetHasEntry(baseNames, baseNameId))
1016 keylen = rpmstrPoolStrlen(tspool, baseNameId);
1017 baseName = rpmstrPoolStr(tspool, baseNameId);
1019 keylen++; /* XXX "/" fixup. */
1020 rpmdbExtendIterator(mi, baseName, keylen);
1021 rpmStringSetAddEntry(baseNames, baseNameId);
1024 rpmfilesFree(files);
1027 rpmStringSetFree(baseNames);
1029 rpmdbSortIterator(mi);
1030 /* iterator is now sorted by (recnum, filenum) */
1034 /* Check files in the transactions against the rpmdb
1035 * Lookup all files with the same basename in the rpmdb
1036 * and then check for matching finger prints
1037 * @param ts transaction set
1038 * @param fpc global finger print cache
1041 void checkInstalledFiles(rpmts ts, uint64_t fileCount, fingerPrintCache fpc)
1043 tsMembers tsmem = rpmtsMembers(ts);
1048 unsigned int fileNum;
1050 rpmdbMatchIterator mi;
1051 Header h, newheader;
1053 rpmlog(RPMLOG_DEBUG, "computing file dispositions\n");
1055 mi = rpmFindBaseNamesInDB(ts, fileCount);
1057 /* For all installed headers with matching basename's ... */
1061 if (rpmdbGetIteratorCount(mi) == 0) {
1062 mi = rpmdbFreeIterator(mi);
1066 /* Loop over all packages from the rpmdb */
1067 h = newheader = rpmdbNextIterator(mi);
1069 headerGetFlags hgflags = HEADERGET_MINMEM;
1070 struct rpmtd_s bnames, dnames, dindexes, ostates;
1071 fingerPrint *fpp = NULL;
1072 unsigned int installedPkg;
1073 int beingRemoved = 0;
1074 rpmfiles otherFi = NULL;
1075 rpmte *removedPkg = NULL;
1077 /* Is this package being removed? */
1078 installedPkg = rpmdbGetIteratorOffset(mi);
1079 if (packageHashGetEntry(tsmem->removedPackages, installedPkg,
1080 &removedPkg, NULL, NULL)) {
1082 otherFi = rpmteFiles(removedPkg[0]);
1086 /* For packages being removed we can use its rpmfi to avoid all this */
1087 if (!beingRemoved) {
1088 headerGet(h, RPMTAG_BASENAMES, &bnames, hgflags);
1089 headerGet(h, RPMTAG_DIRNAMES, &dnames, hgflags);
1090 headerGet(h, RPMTAG_DIRINDEXES, &dindexes, hgflags);
1091 headerGet(h, RPMTAG_FILESTATES, &ostates, hgflags);
1094 /* loop over all interesting files in that package */
1097 struct rpmffi_s * recs;
1099 const char * dirName;
1100 const char * baseName;
1102 /* lookup finger print for this file */
1103 fileNum = rpmdbGetIteratorFileNum(mi);
1104 if (!beingRemoved) {
1105 rpmtdSetIndex(&bnames, fileNum);
1106 rpmtdSetIndex(&dindexes, fileNum);
1107 rpmtdSetIndex(&dnames, *rpmtdGetUint32(&dindexes));
1108 rpmtdSetIndex(&ostates, fileNum);
1110 dirName = rpmtdGetString(&dnames);
1111 baseName = rpmtdGetString(&bnames);
1113 fpLookup(fpc, dirName, baseName, &fpp);
1116 fpp = rpmfilesFps(otherFi);
1120 /* search for files in the transaction with same finger print */
1121 fpCacheGetByFp(fpc, fpp, fpIx, &recs, &numRecs);
1123 for (j = 0; j < numRecs; j++) {
1126 fs = rpmteGetFileStates(p);
1128 /* Determine the fate of each file. */
1129 switch (rpmteType(p)) {
1132 /* XXX What to do if this fails? */
1133 otherFi = rpmfilesNew(NULL, h, RPMTAG_BASENAMES, RPMFI_KEEPHEADER);
1135 handleInstInstalledFile(ts, p, fi, recs[j].fileno,
1136 h, otherFi, fileNum, beingRemoved);
1139 if (!beingRemoved) {
1140 if (*rpmtdGetChar(&ostates) == RPMFILE_STATE_NORMAL)
1141 rpmfsSetAction(fs, recs[j].fileno, FA_SKIP);
1148 newheader = rpmdbNextIterator(mi);
1150 } while (newheader==h);
1152 otherFi = rpmfilesFree(otherFi);
1153 if (!beingRemoved) {
1154 rpmtdFreeData(&ostates);
1155 rpmtdFreeData(&bnames);
1156 rpmtdFreeData(&dnames);
1157 rpmtdFreeData(&dindexes);
1164 rpmdbFreeIterator(mi);
1167 #define badArch(_a) (rpmMachineScore(RPM_MACHTABLE_INSTARCH, (_a)) == 0)
1168 #define badOs(_a) (rpmMachineScore(RPM_MACHTABLE_INSTOS, (_a)) == 0)
1171 * For packages being installed:
1172 * - verify package arch/os.
1173 * - verify package epoch:version-release is newer.
1175 static rpmps checkProblems(rpmts ts)
1177 rpm_color_t tscolor = rpmtsColor(ts);
1178 rpmprobFilterFlags probFilter = rpmtsFilterFlags(ts);
1179 rpmstrPool tspool = rpmtsPool(ts);
1180 rpmtsi pi = rpmtsiInit(ts);
1183 /* The ordering doesn't matter here */
1184 /* XXX Only added packages need be checked. */
1185 rpmlog(RPMLOG_DEBUG, "sanity checking %d elements\n", rpmtsNElements(ts));
1186 while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) {
1188 if (!(probFilter & RPMPROB_FILTER_IGNOREARCH) && badArch(rpmteA(p)))
1189 rpmteAddProblem(p, RPMPROB_BADARCH, rpmteA(p), NULL, 0);
1191 if (!(probFilter & RPMPROB_FILTER_IGNOREOS) && badOs(rpmteO(p)))
1192 rpmteAddProblem(p, RPMPROB_BADOS, rpmteO(p), NULL, 0);
1194 if (!(probFilter & RPMPROB_FILTER_OLDPACKAGE)) {
1196 rpmdbMatchIterator mi;
1197 mi = rpmtsInitIterator(ts, RPMDBI_NAME, rpmteN(p), 0);
1198 while ((h = rpmdbNextIterator(mi)) != NULL)
1199 ensureOlder(tspool, p, h);
1200 rpmdbFreeIterator(mi);
1203 if (!(probFilter & RPMPROB_FILTER_REPLACEPKG)) {
1205 rpmdbMatchIterator mi;
1206 mi = rpmtsPrunedIterator(ts, RPMDBI_NAME, rpmteN(p), 1);
1207 rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP, rpmteE(p));
1208 rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP, rpmteV(p));
1209 rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP, rpmteR(p));
1211 rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_STRCMP, rpmteA(p));
1212 rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_STRCMP, rpmteO(p));
1215 if ((h = rpmdbNextIterator(mi)) != NULL) {
1216 rpmteAddProblem(p, RPMPROB_PKG_INSTALLED, NULL, NULL,
1217 headerGetInstance(h));
1219 rpmdbFreeIterator(mi);
1222 if (!(probFilter & RPMPROB_FILTER_FORCERELOCATE))
1223 rpmteAddRelocProblems(p);
1226 return rpmtsProblems(ts);
1230 * Run pre/post transaction scripts for transaction set
1231 * param ts Transaction set
1232 * param goal PKG_PRETRANS/PKG_POSTTRANS
1233 * return 0 on success
1235 static int runTransScripts(rpmts ts, pkgGoal goal)
1239 rpmtsi pi = rpmtsiInit(ts);
1240 rpmElementTypes types = TR_ADDED;
1242 if (goal == PKG_TRANSFILETRIGGERUN)
1245 while ((p = rpmtsiNext(pi, types)) != NULL) {
1246 rc += rpmteProcess(p, goal, i++);
1252 static int rpmtsSetup(rpmts ts, rpmprobFilterFlags ignoreSet)
1254 rpm_tid_t tid = (rpm_tid_t) time(NULL);
1255 int dbmode = (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) ? O_RDONLY : (O_RDWR|O_CREAT);
1257 if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS)
1258 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
1259 if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERS)
1260 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransTriggers));
1262 if (rpmtsFlags(ts) & (RPMTRANS_FLAG_JUSTDB | RPMTRANS_FLAG_TEST))
1263 (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
1266 * Make sure the database is open RDWR for package install/erase.
1267 * Note that we initialize chroot state here even if it's just "/" as
1268 * this ensures we can successfully perform open(".") which is
1269 * required to reliably restore cwd after Lua scripts.
1271 if (rpmtsOpenDB(ts, dbmode) || rpmChrootSet(rpmtsRootDir(ts)))
1274 ts->ignoreSet = ignoreSet;
1275 (void) rpmtsSetTid(ts, tid);
1277 /* Get available space on mounted file systems. */
1278 (void) rpmtsInitDSI(ts);
1283 static int rpmtsFinish(rpmts ts)
1285 return rpmChrootSet(NULL);
1288 static int rpmtsPrepare(rpmts ts)
1290 tsMembers tsmem = rpmtsMembers(ts);
1294 uint64_t fileCount = countFiles(ts);
1295 const char *dbhome = NULL;
1298 fingerPrintCache fpc = fpCacheCreate(fileCount/2 + 10001, rpmtsPool(ts));
1300 rpmlog(RPMLOG_DEBUG, "computing %" PRIu64 " file fingerprints\n", fileCount);
1302 /* Reset actions, set skip for netshared paths and excluded files */
1303 pi = rpmtsiInit(ts);
1304 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1305 rpmfiles files = rpmteFiles(p);
1306 if (rpmfilesFC(files) > 0) {
1307 rpmfs fs = rpmteGetFileStates(p);
1308 /* Ensure clean state, this could get called more than once. */
1309 rpmfsResetActions(fs);
1310 if (rpmteType(p) == TR_ADDED) {
1311 skipInstallFiles(ts, files, fs);
1313 skipEraseFiles(ts, files, fs);
1316 rpmfilesFree(files);
1320 /* Open rpmdb & enter chroot for fingerprinting if necessary */
1321 if (rpmdbOpenAll(ts->rdb) || rpmChrootIn()) {
1326 rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_START, 6, tsmem->orderCount);
1327 /* Add fingerprint for each file not skipped. */
1328 fpCachePopulate(fpc, ts, fileCount);
1329 /* check against files in the rpmdb */
1330 checkInstalledFiles(ts, fileCount, fpc);
1332 dbhome = rpmdbHome(rpmtsGetRdb(ts));
1333 /* If we can't stat, ignore db growth. Probably not right but... */
1334 if (dbhome && stat(dbhome, &dbstat))
1337 pi = rpmtsiInit(ts);
1338 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1339 rpmfiles files = rpmteFiles(p);;
1341 continue; /* XXX can't happen */
1343 (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
1344 /* check files in ts against each other and update disk space
1345 needs on each partition for this package. */
1346 handleOverlappedFiles(ts, fpc, p, files);
1348 /* Check added package has sufficient space on each partition used. */
1349 if (rpmteType(p) == TR_ADDED) {
1351 * Try to estimate space needed for rpmdb growth: guess that the
1352 * db grows 4 times the header size (indexes and all).
1355 int64_t hsize = rpmteHeaderSize(p) * 4;
1356 rpmtsUpdateDSI(ts, dbstat.st_dev, dbhome,
1357 hsize, 0, 0, FA_CREATE);
1360 rpmtsCheckDSIProblems(ts, p);
1362 (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
1363 rpmfilesFree(files);
1366 rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_STOP, 6, tsmem->orderCount);
1368 /* return from chroot if done earlier */
1372 /* On actual transaction, file info sets are not needed after this */
1373 if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS))) {
1374 pi = rpmtsiInit(ts);
1375 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1388 * Transaction main loop: install and remove packages
1390 static int rpmtsProcess(rpmts ts)
1396 pi = rpmtsiInit(ts);
1397 while ((p = rpmtsiNext(pi, 0)) != NULL) {
1400 rpmlog(RPMLOG_DEBUG, "========== +++ %s %s-%s 0x%x\n",
1401 rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p));
1403 failed = rpmteProcess(p, rpmteType(p), i++);
1405 rpmlog(RPMLOG_ERR, "%s: %s %s\n", rpmteNEVRA(p),
1406 rpmteTypeString(p), failed > 1 ? _("skipped") : _("failed"));
1414 rpmRC rpmtsSetupTransactionPlugins(rpmts ts)
1416 rpmRC rc = RPMRC_OK;
1417 ARGV_t files = NULL;
1419 char *dsoPath = NULL;
1422 * Assume allocated equals initialized. There are some oddball cases
1423 * (verification of non-installed package) where this is not true
1424 * currently but that's not a new issue.
1426 if ((rpmtsFlags(ts) & RPMTRANS_FLAG_NOPLUGINS) || rpmPluginsGetCount(rpmtsPlugins(ts)) != 0)
1429 dsoPath = rpmExpand("%{__plugindir}/*.so", NULL);
1430 if (rpmGlob(dsoPath, &nfiles, &files) == 0) {
1431 rpmPlugins tsplugins = rpmtsPlugins(ts);
1432 for (int i = 0; i < nfiles; i++) {
1433 char *bn = basename(files[i]);
1434 bn[strlen(bn)-strlen(".so")] = '\0';
1435 if (rpmpluginsAddPlugin(tsplugins, "transaction", bn) == RPMRC_FAIL)
1437 /* any configured plugin failing to load is a failure */
1438 // temporally make the loading policy relaxed: no failures
1439 //refer to commit id: 3959da1846227711d97c17495aa4779e653a1b3a
1443 files = argvFree(files);
1450 * Run a scriptlet with args.
1452 * Run a script with an interpreter. If the interpreter is not specified,
1453 * /bin/sh will be used. If the interpreter is /bin/sh, then the args from
1454 * the header will be ignored, passing instead arg1 and arg2.
1456 * @param ts transaction set
1457 * @param te transaction element
1458 * @param prefixes install prefixes
1459 * @param script scriptlet from header
1460 * @param arg1 no. instances of package installed after scriptlet exec
1462 * @param arg2 ditto, but for the target package
1463 * @return 0 on success
1465 rpmRC runScript(rpmts ts, rpmte te, Header h, ARGV_const_t prefixes,
1466 rpmScript script, int arg1, int arg2)
1469 rpmRC stoprc, rc = RPMRC_OK;
1470 rpmTagVal stag = rpmScriptTag(script);
1472 int warn_only = (stag != RPMTAG_PREIN &&
1473 stag != RPMTAG_PREUN &&
1474 stag != RPMTAG_PRETRANS &&
1475 stag != RPMTAG_VERIFYSCRIPT);
1477 /* Fake up a transaction element for triggers from rpmdb */
1479 te = rpmteNew(ts, h, TR_REMOVED, NULL, NULL);
1480 rpmteSetHeader(te, h);
1483 sfd = rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_START, stag, 0);
1485 sfd = rpmtsScriptFd(ts);
1487 rpmswEnter(rpmtsOp(ts, RPMTS_OP_SCRIPTLETS), 0);
1488 rc = rpmScriptRun(script, arg1, arg2, sfd,
1489 prefixes, warn_only, rpmtsPlugins(ts));
1490 rpmswExit(rpmtsOp(ts, RPMTS_OP_SCRIPTLETS), 0);
1492 /* Map warn-only errors to "notfound" for script stop callback */
1493 stoprc = (rc != RPMRC_OK && warn_only) ? RPMRC_NOTFOUND : rc;
1494 rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_STOP, stag, stoprc);
1497 * Notify callback for all errors. "total" abused for warning/error,
1498 * rc only reflects whether the condition prevented install/erase
1499 * (which is only happens with %prein and %preun scriptlets) or not.
1501 if (rc != RPMRC_OK) {
1505 rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_ERROR, stag, rc);
1514 int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
1516 int rc = -1; /* assume failure */
1517 tsMembers tsmem = rpmtsMembers(ts);
1519 rpmps tsprobs = NULL;
1520 int TsmPreDone = 0; /* TsmPre hook hasn't been called */
1521 /* Ignore SIGPIPE for the duration of transaction */
1522 rpmsqAction_t oact = rpmsqSetAction(SIGPIPE, RPMSQ_IGN);
1524 /* Force default 022 umask during transaction for consistent results */
1525 mode_t oldmask = umask(022);
1527 /* Empty transaction, nothing to do */
1528 if (rpmtsNElements(ts) <= 0) {
1533 /* If we are in test mode, then there's no need for transaction lock. */
1534 if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
1535 if (!(txn = rpmtxnBegin(ts, RPMTXN_WRITE))) {
1540 /* Setup flags and such, open the DB */
1541 if (rpmtsSetup(ts, ignoreSet)) {
1545 /* Check package set for problems */
1546 tsprobs = checkProblems(ts);
1548 /* Run pre transaction hook for all plugins */
1550 if (rpmpluginsCallTsmPre(rpmtsPlugins(ts), ts) == RPMRC_FAIL) {
1554 /* Run %pretrans scripts, but only if there are no known problems up to
1555 * this point and not disabled otherwise. This is evil as it runs before
1556 * fingerprinting and problem checking and is best avoided.
1558 if (!((rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_NOPRETRANS))
1559 || (rpmpsNumProblems(tsprobs)))) {
1560 rpmlog(RPMLOG_DEBUG, "running pre-transaction scripts\n");
1561 runTransScripts(ts, PKG_PRETRANS);
1563 tsprobs = rpmpsFree(tsprobs);
1565 /* Compute file disposition for each package in transaction set. */
1566 if (rpmtsPrepare(ts)) {
1569 /* Check again for problems (now including file conflicts, duh */
1570 tsprobs = rpmtsProblems(ts);
1572 /* If unfiltered problems exist, free memory and return. */
1573 if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS) || (rpmpsNumProblems(tsprobs))) {
1574 rc = tsmem->orderCount;
1578 /* Free up memory taken by problem sets */
1579 tsprobs = rpmpsFree(tsprobs);
1580 rpmtsCleanProblems(ts);
1583 * Free up the global string pool unless we expect it to be needed
1584 * again. During the transaction, private pools will be used for
1587 if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS)))
1588 tsmem->pool = rpmstrPoolFree(tsmem->pool);
1590 /* Run %transfiletriggerun scripts unless disabled */
1591 if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_NOPRETRANS|
1592 RPMTRANS_FLAG_NOTRIGGERUN))) {
1594 runFileTriggers(ts, NULL, RPMSENSE_TRIGGERUN,
1595 RPMSCRIPT_TRANSFILETRIGGER, 0);
1596 runTransScripts(ts, PKG_TRANSFILETRIGGERUN);
1599 /* Actually install and remove packages, get final exit code */
1600 rc = rpmtsProcess(ts) ? -1 : 0;
1602 /* Run %posttrans scripts unless disabled */
1603 if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS))) {
1604 rpmlog(RPMLOG_DEBUG, "running post-transaction scripts\n");
1605 runTransScripts(ts, PKG_POSTTRANS);
1608 /* Run %transfiletriggerpostun scripts unless disabled */
1609 if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS|RPMTRANS_FLAG_NOTRIGGERIN))) {
1610 runFileTriggers(ts, NULL, RPMSENSE_TRIGGERIN, RPMSCRIPT_TRANSFILETRIGGER, 0);
1612 if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS|RPMTRANS_FLAG_NOTRIGGERPOSTUN))) {
1613 runPostUnTransFileTrigs(ts);
1616 /* Run %transfiletriggerin scripts unless disabled */
1617 if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS|RPMTRANS_FLAG_NOTRIGGERIN))) {
1618 runTransScripts(ts, PKG_TRANSFILETRIGGERIN);
1621 /* Run post transaction hook for all plugins */
1622 if (TsmPreDone) /* If TsmPre hook has been called, call the TsmPost hook */
1623 rpmpluginsCallTsmPost(rpmtsPlugins(ts), ts, rc);
1626 (void) umask(oldmask);
1627 (void) rpmtsFinish(ts);
1630 /* Restore SIGPIPE *after* unblocking signals in rpmtxnEnd() */
1631 rpmsqSetAction(SIGPIPE, oact);