michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame SOURCES/rpm-4.16.1.3-fix-spurious-transfiletriggerpostun-execution.patch

a5e32e
From 8c37dff4ce9c887eda5ad61f78001e87473002ed Mon Sep 17 00:00:00 2001
a5e32e
From: Panu Matilainen <pmatilai@redhat.com>
a5e32e
Date: Tue, 16 Nov 2021 11:49:18 +0200
a5e32e
Subject: [PATCH] Fix spurious %transfiletriggerpostun execution
a5e32e
 (RhBug:2023311)
a5e32e
a5e32e
If a package has multiple %transfiletriggerpostun triggers, any one
a5e32e
of them matching would cause all of them to run, due to disconnect
a5e32e
in the intel gathering stage: we'd gather all the headers with matching
a5e32e
files into a lump, and then add any postun triggers found in them,
a5e32e
but this loses the triggering file information and causes all postuns
a5e32e
to run.
a5e32e
a5e32e
The triggers need to be added while looping over the file matches,
a5e32e
like runFileTriggers() does. Doing so actually simplifies the code.
a5e32e
These should really be unified to use the same code, but leaving
a5e32e
that exercise to another rainy day.
a5e32e
a5e32e
Combined with 0988ccb53abf426587d228df5c60c4042da71999 (fix-up).
a5e32e
---
a5e32e
 lib/rpmtriggers.c | 65 ++++++++++++++++++++++++-----------------------
a5e32e
 1 file changed, 33 insertions(+), 32 deletions(-)
a5e32e
a5e32e
diff --git a/lib/rpmtriggers.c b/lib/rpmtriggers.c
a5e32e
index fc809a65e..8d8f57450 100644
a5e32e
--- a/lib/rpmtriggers.c
a5e32e
+++ b/lib/rpmtriggers.c
a5e32e
@@ -97,19 +97,39 @@ static void rpmtriggersSortAndUniq(rpmtriggers trigs)
a5e32e
     }
a5e32e
 }
a5e32e
 
a5e32e
+static void addTriggers(rpmts ts, Header trigH, rpmsenseFlags filter,
a5e32e
+			const char *prefix)
a5e32e
+{
a5e32e
+    int tix = 0;
a5e32e
+    rpmds ds;
a5e32e
+    rpmds triggers = rpmdsNew(trigH, RPMTAG_TRANSFILETRIGGERNAME, 0);
a5e32e
+
a5e32e
+    while ((ds = rpmdsFilterTi(triggers, tix))) {
a5e32e
+	if ((rpmdsNext(ds) >= 0) && (rpmdsFlags(ds) & filter) &&
a5e32e
+		strcmp(prefix, rpmdsN(ds)) == 0) {
a5e32e
+	    struct rpmtd_s priorities;
a5e32e
+
a5e32e
+	    if (headerGet(trigH, RPMTAG_TRANSFILETRIGGERPRIORITIES,
a5e32e
+			&priorities, HEADERGET_MINMEM)) {
a5e32e
+		rpmtdSetIndex(&priorities, tix);
a5e32e
+		rpmtriggersAdd(ts->trigs2run, headerGetInstance(trigH),
a5e32e
+				tix, *rpmtdGetUint32(&priorities));
a5e32e
+	    }
a5e32e
+	}
a5e32e
+	rpmdsFree(ds);
a5e32e
+	tix++;
a5e32e
+    }
a5e32e
+    rpmdsFree(triggers);
a5e32e
+}
a5e32e
+
a5e32e
 void rpmtriggersPrepPostUnTransFileTrigs(rpmts ts, rpmte te)
a5e32e
 {
a5e32e
-    rpmdbMatchIterator mi;
a5e32e
     rpmdbIndexIterator ii;
a5e32e
-    Header trigH;
a5e32e
     const void *key;
a5e32e
     size_t keylen;
a5e32e
     rpmfiles files;
a5e32e
-    rpmds rpmdsTriggers;
a5e32e
-    rpmds rpmdsTrigger;
a5e32e
 
a5e32e
     ii = rpmdbIndexIteratorInit(rpmtsGetRdb(ts), RPMDBI_TRANSFILETRIGGERNAME);
a5e32e
-    mi = rpmdbNewIterator(rpmtsGetRdb(ts), RPMDBI_PACKAGES);
a5e32e
     files = rpmteFiles(te);
a5e32e
 
a5e32e
     /* Iterate over file triggers in rpmdb */
a5e32e
@@ -121,39 +141,20 @@ void rpmtriggersPrepPostUnTransFileTrigs(rpmts ts, rpmte te)
a5e32e
 	rpmfi fi = rpmfilesFindPrefix(files, pfx);
a5e32e
 	while (rpmfiNext(fi) >= 0) {
a5e32e
 	    if (RPMFILE_IS_INSTALLED(rpmfiFState(fi))) {
a5e32e
-		/* If yes then store it */
a5e32e
-		rpmdbAppendIterator(mi, rpmdbIndexIteratorPkgOffsets(ii),
a5e32e
-				rpmdbIndexIteratorNumPkgs(ii));
a5e32e
+		unsigned int npkg = rpmdbIndexIteratorNumPkgs(ii);
a5e32e
+		const unsigned int *offs = rpmdbIndexIteratorPkgOffsets(ii);
a5e32e
+		/* Save any postun triggers matching this prefix */
a5e32e
+		for (int i = 0; i < npkg; i++) {
a5e32e
+		    Header h = rpmdbGetHeaderAt(rpmtsGetRdb(ts), offs[i]);
a5e32e
+		    addTriggers(ts, h, RPMSENSE_TRIGGERPOSTUN, pfx);
a5e32e
+		    headerFree(h);
a5e32e
+		}
a5e32e
 		break;
a5e32e
 	    }
a5e32e
 	}
a5e32e
 	rpmfiFree(fi);
a5e32e
     }
a5e32e
     rpmdbIndexIteratorFree(ii);
a5e32e
-
a5e32e
-    if (rpmdbGetIteratorCount(mi)) {
a5e32e
-	/* Filter triggers and save only trans postun triggers into ts */
a5e32e
-	while ((trigH = rpmdbNextIterator(mi)) != NULL) {
a5e32e
-	    int tix = 0;
a5e32e
-	    rpmdsTriggers = rpmdsNew(trigH, RPMTAG_TRANSFILETRIGGERNAME, 0);
a5e32e
-	    while ((rpmdsTrigger = rpmdsFilterTi(rpmdsTriggers, tix))) {
a5e32e
-		if ((rpmdsNext(rpmdsTrigger) >= 0) &&
a5e32e
-		    (rpmdsFlags(rpmdsTrigger) & RPMSENSE_TRIGGERPOSTUN)) {
a5e32e
-		    struct rpmtd_s priorities;
a5e32e
-
a5e32e
-		    headerGet(trigH, RPMTAG_TRANSFILETRIGGERPRIORITIES,
a5e32e
-				&priorities, HEADERGET_MINMEM);
a5e32e
-		    rpmtdSetIndex(&priorities, tix);
a5e32e
-		    rpmtriggersAdd(ts->trigs2run, rpmdbGetIteratorOffset(mi),
a5e32e
-				    tix, *rpmtdGetUint32(&priorities));
a5e32e
-		}
a5e32e
-		rpmdsFree(rpmdsTrigger);
a5e32e
-		tix++;
a5e32e
-	    }
a5e32e
-	    rpmdsFree(rpmdsTriggers);
a5e32e
-	}
a5e32e
-    }
a5e32e
-    rpmdbFreeIterator(mi);
a5e32e
     rpmfilesFree(files);
a5e32e
 }
a5e32e
 
a5e32e
-- 
a5e32e
2.35.1
a5e32e