Blob Blame History Raw
From 2d85f74afc3ccfa584dd8f0981673ff2b06277d1 Mon Sep 17 00:00:00 2001
Message-Id: <2d85f74afc3ccfa584dd8f0981673ff2b06277d1.1643803240.git.pmatilai@redhat.com>
From: Panu Matilainen <pmatilai@redhat.com>
Date: Wed, 2 Feb 2022 13:46:23 +0200
Subject: [PATCH] Really fix spurious %transfiletriggerpostun execution
 (RhBug:2023311)

Commit b3d672a5523dfec033160e5cc866432a0e808649 got the base reasoning
in the ballpark but the code all wrong, introducing a severe performance
regression without actually fixing what it claimed to.

The missing incredient is actually comparing the current prefix with the
triggers in matched package (trying to describe this makes my head
spin): a package may have multiple triggers on multiple prefixes and
we need to make sure we only execute triggers of this type, from this
prefix.

Fixes: b3d672a5523dfec033160e5cc866432a0e808649
---
 lib/rpmtriggers.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/rpmtriggers.c b/lib/rpmtriggers.c
index 6fe4db65d..3f8fa22d0 100644
--- a/lib/rpmtriggers.c
+++ b/lib/rpmtriggers.c
@@ -97,14 +97,16 @@ static void rpmtriggersSortAndUniq(rpmtriggers trigs)
     }
 }
 
-static void addTriggers(rpmts ts, Header trigH, rpmsenseFlags filter)
+static void addTriggers(rpmts ts, Header trigH, rpmsenseFlags filter,
+			const char *prefix)
 {
     int tix = 0;
     rpmds ds;
     rpmds triggers = rpmdsNew(trigH, RPMTAG_TRANSFILETRIGGERNAME, 0);
 
     while ((ds = rpmdsFilterTi(triggers, tix))) {
-	if ((rpmdsNext(ds) >= 0) && (rpmdsFlags(ds) & filter)) {
+	if ((rpmdsNext(ds) >= 0) && (rpmdsFlags(ds) & filter) &&
+		strcmp(prefix, rpmdsN(ds)) == 0) {
 	    struct rpmtd_s priorities;
 
 	    if (headerGet(trigH, RPMTAG_TRANSFILETRIGGERPRIORITIES,
@@ -141,12 +143,13 @@ void rpmtriggersPrepPostUnTransFileTrigs(rpmts ts, rpmte te)
 	    if (RPMFILE_IS_INSTALLED(rpmfiFState(fi))) {
 		unsigned int npkg = rpmdbIndexIteratorNumPkgs(ii);
 		const unsigned int *offs = rpmdbIndexIteratorPkgOffsets(ii);
-		/* Save any matching postun triggers */
+		/* Save any postun triggers matching this prefix */
 		for (int i = 0; i < npkg; i++) {
 		    Header h = rpmdbGetHeaderAt(rpmtsGetRdb(ts), offs[i]);
-		    addTriggers(ts, h, RPMSENSE_TRIGGERPOSTUN);
+		    addTriggers(ts, h, RPMSENSE_TRIGGERPOSTUN, pfx);
 		    headerFree(h);
 		}
+		break;
 	    }
 	}
 	rpmfiFree(fi);
-- 
2.34.1