richardphibel / rpms / rpm

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