michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 5 months ago
Clone

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

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