Fix duplicate dependency checking on build
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 20 Aug 2009 10:02:05 +0000 (13:02 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 20 Aug 2009 10:02:05 +0000 (13:02 +0300)
- Broken by commit af8b41c64af39ce07d85fcd92fa78d566747d815 which
  simplified too much.
- There's no guarantee that rpmdsNew() returns a sorted dependency set
  so rpmdsFind() doesn't work correctly here. Walk the ds manually instead.
- With multiple triggers of same type, identical trigger conditions on
  different trigger script were seen as duplicates (RhBug:490378)
- Split the duplicate checking to separate helper function for clarity

build/reqprov.c

index 1e69bd2..ba6a1e8 100644 (file)
@@ -9,6 +9,38 @@
 #include <rpm/rpmbuild.h>
 #include "debug.h"
 
+static int isNewDep(Header h, rpmTag nametag,
+                 const char *N, const char *EVR, rpmsenseFlags Flags,
+                 rpmTag indextag, uint32_t index)
+{
+    int new = 1;
+    struct rpmtd_s idx;
+    rpmds ads = rpmdsNew(h, nametag, 0);
+    rpmds bds = rpmdsSingle(nametag, N, EVR, Flags);
+
+    if (indextag) {
+       headerGet(h, indextag, &idx, HEADERGET_MINMEM);
+    }
+
+    /* XXX there's no guarantee the ds is sorted here so rpmdsFind() wont do */
+    rpmdsInit(ads);
+    while (new && rpmdsNext(ads) >= 0) {
+       if (strcmp(rpmdsN(ads), rpmdsN(bds))) continue;
+       if (strcmp(rpmdsEVR(ads), rpmdsEVR(bds))) continue;
+       if (rpmdsFlags(ads) != rpmdsFlags(bds)) continue;
+       if (indextag && rpmtdSetIndex(&idx, rpmdsIx(ads)) >= 0 &&
+                       rpmtdGetNumber(&idx) != index) continue;
+       new = 0;
+    }
+    
+    if (indextag) {
+       rpmtdFreeData(&idx);
+    }
+    rpmdsFree(ads);
+    rpmdsFree(bds);
+    return new;
+}
+
 int addReqProv(rpmSpec spec, Header h, rpmTag tagN,
                const char * N, const char * EVR, rpmsenseFlags Flags,
                uint32_t index)
@@ -55,28 +87,18 @@ int addReqProv(rpmSpec spec, Header h, rpmTag tagN,
     if (EVR == NULL)
        EVR = "";
     
-    /* Check for duplicate dependencies. */
-    rpmds hds = rpmdsNew(h, nametag, 0);
-    rpmds newds = rpmdsSingle(nametag, N, EVR, Flags);
-    /* already got it, don't bother */
-    if (rpmdsFind(hds, newds) >= 0) {
-       goto exit;
-    }
-
-    /* Add this dependency. */
-    headerPutString(h, nametag, N);
-    if (flagtag) {
-       headerPutString(h, versiontag, EVR);
-       headerPutUint32(h, flagtag, &Flags, 1);
-    }
-    if (indextag) {
-       headerPutUint32(h, indextag, &index, 1);
+    /* Avoid adding duplicate dependencies. */
+    if (isNewDep(h, nametag, N, EVR, Flags, indextag, index)) {
+       headerPutString(h, nametag, N);
+       if (flagtag) {
+           headerPutString(h, versiontag, EVR);
+           headerPutUint32(h, flagtag, &Flags, 1);
+       }
+       if (indextag) {
+           headerPutUint32(h, indextag, &index, 1);
+       }
     }
 
-exit:
-    rpmdsFree(hds);
-    rpmdsFree(newds);
-       
     return 0;
 }