Move the entire fingerprint cache population into fprint.c
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 13 Sep 2012 19:19:40 +0000 (22:19 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 14 Sep 2012 10:32:58 +0000 (13:32 +0300)
- Rename addFingerprints() to fpCachePopulate() and move into fprint.c.
  This doesn't really belong here as it requires fprint becoming aware
  of transactions and all, but at least these are all controlled API
  accesses unlike where in transaction.c this was messing with somebody
  elses data structures directly.
- Move the by-fingerprint creation to fpCachePopulate() so it gets
  lazily done as needed and copy the original hash-size heuristics
  back here.

lib/fprint.c
lib/fprint.h
lib/transaction.c

index f72a149..e6aa42b 100644 (file)
@@ -5,9 +5,12 @@
 #include "system.h"
 
 #include <rpm/rpmfileutil.h>   /* for rpmCleanPath */
+#include <rpm/rpmts.h>
+#include <rpm/rpmdb.h>
 
 #include "lib/rpmdb_internal.h"
 #include "lib/rpmfi_internal.h"
+#include "lib/rpmte_internal.h"
 #include "lib/fprint.h"
 #include "lib/misc.h"
 #include "debug.h"
@@ -40,8 +43,6 @@ fingerPrintCache fpCacheCreate(int sizeHint)
     fpc->ht = rpmFpEntryHashCreate(sizeHint, rstrhash, strcmp,
                                   (rpmFpEntryHashFreeKey)free,
                                   (rpmFpEntryHashFreeData)free);
-    fpc->fp = rpmFpHashCreate(sizeHint, fpHashFunction, fpEqual,
-                                 NULL, NULL);
     return fpc;
 }
 
@@ -368,3 +369,71 @@ int fpCacheGetByFp(fingerPrintCache cache, struct fingerPrint_s * fp,
 {
     return rpmFpHashGetEntry(cache->fp, fp, recs, numRecs, NULL);
 }
+
+void fpCachePopulate(fingerPrintCache fpc, rpmts ts, int fileCount)
+{
+    rpmtsi pi;
+    rpmte p;
+    rpmfs fs;
+    rpmfi fi;
+    int i, fc;
+
+    if (fpc->fp == NULL)
+       fpc->fp = rpmFpHashCreate(fileCount/2 + 10001, fpHashFunction, fpEqual,
+                                 NULL, NULL);
+
+    rpmFpHash symlinks = rpmFpHashCreate(fileCount/16+16, fpHashFunction, fpEqual, NULL, NULL);
+
+    pi = rpmtsiInit(ts);
+    while ((p = rpmtsiNext(pi, 0)) != NULL) {
+       (void) rpmdbCheckSignals();
+
+       if ((fi = rpmteFI(p)) == NULL)
+           continue;   /* XXX can't happen */
+
+       (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
+       rpmfiFpLookup(fi, fpc);
+       fs = rpmteGetFileStates(p);
+       fc = rpmfsFC(fs);
+       /* collect symbolic links */
+       for (i = 0; i < fc; i++) {
+           struct rpmffi_s ffi;
+           char const *linktarget;
+           if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
+               continue;
+           linktarget = rpmfiFLinkIndex(fi, i);
+           if (!(linktarget && *linktarget != '\0'))
+               continue;
+           ffi.p = p;
+           ffi.fileno = i;
+           rpmFpHashAddEntry(symlinks, rpmfiFpsIndex(fi, i), ffi);
+       }
+       (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), fc);
+
+    }
+    rpmtsiFree(pi);
+
+    /* ===============================================
+     * Check fingerprints if they contain symlinks
+     * and add them to the hash table
+     */
+
+    pi = rpmtsiInit(ts);
+    while ((p = rpmtsiNext(pi, 0)) != NULL) {
+       (void) rpmdbCheckSignals();
+
+       fs = rpmteGetFileStates(p);
+       fc = rpmfsFC(fs);
+       (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
+       for (i = 0; i < fc; i++) {
+           if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
+               continue;
+           fpLookupSubdir(symlinks, fpc, p, i);
+       }
+       (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
+    }
+    rpmtsiFree(pi);
+
+    rpmFpHashFree(symlinks);
+}
+
index a52349b..1a1c8e2 100644 (file)
@@ -101,6 +101,9 @@ RPM_GNUC_INTERNAL
 int fpCacheGetByFp(fingerPrintCache cache, struct fingerPrint_s * fp,
                   struct rpmffi_s ** recs, int * numRecs);
 
+RPM_GNUC_INTERNAL
+void fpCachePopulate(fingerPrintCache cache, rpmts ts, int fileCount);
+
 /**
  * Return finger print of a file path.
  * @param cache                pointer to fingerprint cache
index ca1c1af..a8b9606 100644 (file)
@@ -1232,70 +1232,6 @@ static int rpmtsSetupCollections(rpmts ts)
     return 0;
 }
 
-/* Add fingerprint for each file not skipped. */
-static void addFingerprints(rpmts ts, uint64_t fileCount, fingerPrintCache fpc)
-{
-    rpmtsi pi;
-    rpmte p;
-    rpmfs fs;
-    rpmfi fi;
-    int i, fc;
-
-    rpmFpHash symlinks = rpmFpHashCreate(fileCount/16+16, fpHashFunction, fpEqual, NULL, NULL);
-
-    pi = rpmtsiInit(ts);
-    while ((p = rpmtsiNext(pi, 0)) != NULL) {
-       (void) rpmdbCheckSignals();
-
-       if ((fi = rpmteFI(p)) == NULL)
-           continue;   /* XXX can't happen */
-
-       (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
-       rpmfiFpLookup(fi, fpc);
-       fs = rpmteGetFileStates(p);
-       fc = rpmfsFC(fs);
-       /* collect symbolic links */
-       for (i = 0; i < fc; i++) {
-           struct rpmffi_s ffi;
-           char const *linktarget;
-           if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
-               continue;
-           linktarget = rpmfiFLinkIndex(fi, i);
-           if (!(linktarget && *linktarget != '\0'))
-               continue;
-           ffi.p = p;
-           ffi.fileno = i;
-           rpmFpHashAddEntry(symlinks, rpmfiFpsIndex(fi, i), ffi);
-       }
-       (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), fc);
-
-    }
-    rpmtsiFree(pi);
-
-    /* ===============================================
-     * Check fingerprints if they contain symlinks
-     * and add them to the hash table
-     */
-
-    pi = rpmtsiInit(ts);
-    while ((p = rpmtsiNext(pi, 0)) != NULL) {
-       (void) rpmdbCheckSignals();
-
-       fs = rpmteGetFileStates(p);
-       fc = rpmfsFC(fs);
-       (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
-       for (i = 0; i < fc; i++) {
-           if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
-               continue;
-           fpLookupSubdir(symlinks, fpc, p, i);
-       }
-       (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
-    }
-    rpmtsiFree(pi);
-
-    rpmFpHashFree(symlinks);
-}
-
 static int rpmtsSetup(rpmts ts, rpmprobFilterFlags ignoreSet)
 {
     rpm_tid_t tid = (rpm_tid_t) time(NULL);
@@ -1387,7 +1323,8 @@ static int rpmtsPrepare(rpmts ts)
     }
     
     rpmtsNotify(ts, NULL, RPMCALLBACK_TRANS_START, 6, tsmem->orderCount);
-    addFingerprints(ts, fileCount, fpc);
+    /* Add fingerprint for each file not skipped. */
+    fpCachePopulate(fpc, ts, fileCount);
     /* check against files in the rpmdb */
     checkInstalledFiles(ts, fileCount, fpc);