summaryrefslogtreecommitdiff
path: root/lib/psm.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2011-06-01 10:00:04 +0300
committerPanu Matilainen <pmatilai@redhat.com>2011-06-01 10:06:18 +0300
commit030e54a666953ee7ba4fee210887d82eb21d4bcf (patch)
tree5172e3f681ccaff6b554b76ac0f75fa013fe363f /lib/psm.c
parentcaa23a97729e7a6e15f26c0722f9ba0e773d3b6c (diff)
downloadrpm-030e54a666953ee7ba4fee210887d82eb21d4bcf.tar.gz
rpm-030e54a666953ee7ba4fee210887d82eb21d4bcf.tar.bz2
rpm-030e54a666953ee7ba4fee210887d82eb21d4bcf.zip
Split the --replacepkgs hack to a helper function and document it
- Makes the huge rpmpsmStage() that little bit smaller, this special-case code does not belong inline there. Also gets rid of couple of dead assignments and unnecessary variable. - Don't bother unless RPMPROB_FILTER_REPLACEPKG is set, it's not terribly expensive but its also wholly unnecessary in the normal case - Document how the dang thing "works"
Diffstat (limited to 'lib/psm.c')
-rw-r--r--lib/psm.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/lib/psm.c b/lib/psm.c
index 04c06e7b9..f91cd7275 100644
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -688,6 +688,31 @@ static int runFsm(rpmpsm psm, FD_t payload)
return (sc ? sc : ec);
}
+/*
+ * --replacepkgs hack: find the header instance we're replacing and
+ * mark it as the db instance of the install element. In PSM_POST,
+ * if an install element already has a db instance, it's removed
+ * before proceeding with the adding the new header to the db.
+ */
+static void markReplacedInstance(rpmts ts, rpmte te)
+{
+ rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_NAME, rpmteN(te), 0);
+ rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP, rpmteE(te));
+ rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP, rpmteV(te));
+ rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP, rpmteR(te));
+ /* XXX shouldn't we also do this on colorless transactions? */
+ if (rpmtsColor(ts)) {
+ rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_STRCMP, rpmteA(te));
+ rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_STRCMP, rpmteO(te));
+ }
+
+ while (rpmdbNextIterator(mi) != NULL) {
+ rpmteSetDBInstance(te, rpmdbGetIteratorOffset(mi));
+ break;
+ }
+ rpmdbFreeIterator(mi);
+}
+
static rpmRC rpmpsmNext(rpmpsm psm, pkgStage nstage)
{
psm->nstage = nstage;
@@ -697,7 +722,6 @@ static rpmRC rpmpsmNext(rpmpsm psm, pkgStage nstage)
static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
{
const rpmts ts = psm->ts;
- rpm_color_t tscolor = rpmtsColor(ts);
rpmfi fi = psm->fi;
rpmRC rc = RPMRC_OK;
@@ -720,31 +744,12 @@ static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
}
if (psm->goal == PKG_INSTALL) {
- rpmdbMatchIterator mi;
- Header oh;
-
psm->scriptArg = psm->npkgs_installed + 1;
- mi = rpmtsInitIterator(ts, RPMDBI_NAME, rpmteN(psm->te), 0);
- rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP,
- rpmteE(psm->te));
- rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP,
- rpmteV(psm->te));
- rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP,
- rpmteR(psm->te));
- if (tscolor) {
- rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_STRCMP,
- rpmteA(psm->te));
- rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_STRCMP,
- rpmteO(psm->te));
- }
+ /* HACK: reinstall abuses te instance to remove old header */
+ if (rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEPKG)
+ markReplacedInstance(ts, psm->te);
- while ((oh = rpmdbNextIterator(mi)) != NULL) {
- rpmteSetDBInstance(psm->te, rpmdbGetIteratorOffset(mi));
- oh = NULL;
- break;
- }
- mi = rpmdbFreeIterator(mi);
rc = RPMRC_OK;
if (rpmtsFlags(ts) & RPMTRANS_FLAG_JUSTDB) break;
@@ -888,6 +893,7 @@ static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
rpm_count_t fc = rpmfsFC(fs);
rpm_fstate_t * fileStates = rpmfsGetStates(fs);
Header h = rpmteHeader(psm->te);
+ rpm_color_t tscolor = rpmtsColor(ts);
if (fileStates != NULL && fc > 0) {
headerPutChar(h, RPMTAG_FILESTATES, fileStates, fc);