rpm/findfplistexclude.diff

115 lines
3.8 KiB
Diff
Raw Normal View History

Allow an "exclude" parameter for rpmdbFindFp, specifying a header
that is to be excluded in the match. Used to speed up package erase
operations.
Also fixes the skipDir problem that made rpm incorrectly delete
files even if another package still references them.
rh#140055
Index: lib/transaction.c
===================================================================
--- lib/transaction.c.orig
+++ lib/transaction.c
@@ -1745,7 +1745,7 @@ rpmMessage(RPMMESS_DEBUG, _("computing f
(void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0);
/* Extract file info for all files in this package from the database. */
matches = xcalloc(fc, sizeof(*matches));
- if (rpmdbFindFpList(rpmtsGetRdb(ts), fi->fps, matches, fc)) {
+ if (rpmdbFindFpListExclude(rpmtsGetRdb(ts), fi->fps, matches, fc, rpmteType(p) == TR_REMOVED ? fi->record : 0)) {
ps = rpmpsFree(ps);
rpmtsFreeLock(lock);
return 1; /* XXX WTFO? */
Index: rpmdb/fprint.h
===================================================================
--- rpmdb/fprint.h.orig
+++ rpmdb/fprint.h
@@ -79,6 +79,12 @@ int rpmdbFindFpList(/*@null@*/ rpmdb db,
/*@modifies db, *matchList, rpmGlobalMacroContext,
fileSystem, internalState @*/;
+int rpmdbFindFpListExclude(/*@null@*/ rpmdb db, fingerPrint * fpList,
+ /*@out@*/ dbiIndexSet * matchList, int numItems, unsigned int exclude)
+ /*@globals rpmGlobalMacroContext, fileSystem, internalState @*/
+ /*@modifies db, *matchList, rpmGlobalMacroContext,
+ fileSystem, internalState @*/;
+
/* Be carefull with the memory... assert(*fullName == '/' || !scareMemory) */
/**
Index: rpmdb/rpmdb.c
===================================================================
--- rpmdb/rpmdb.c.orig
+++ rpmdb/rpmdb.c
@@ -2358,7 +2358,7 @@ static void rpmdbSortIterator(/*@null@*/
}
/*@-bounds@*/ /* LCL: segfault */
-static int rpmdbGrowIterator(/*@null@*/ rpmdbMatchIterator mi, int fpNum)
+static int rpmdbGrowIterator(/*@null@*/ rpmdbMatchIterator mi, int fpNum, unsigned int exclude)
/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
/*@modifies mi, rpmGlobalMacroContext, fileSystem, internalState @*/
{
@@ -2369,7 +2369,7 @@ static int rpmdbGrowIterator(/*@null@*/
dbiIndexSet set;
int rc;
int xx;
- int i;
+ int i, j;
if (mi == NULL)
return 1;
@@ -2405,6 +2405,25 @@ static int rpmdbGrowIterator(/*@null@*/
set = NULL;
(void) dbt2set(dbi, data, &set);
+
+ /* prune the set against exclude */
+ for (i = j = 0; i < set->count; i++) {
+ if (exclude && set->recs[i].hdrNum == exclude)
+ continue;
+ if (i != j)
+ set->recs[j] = set->recs[i];
+ j++;
+ }
+ if (j == 0) {
+#ifdef SQLITE_HACK
+ xx = dbiCclose(dbi, dbcursor, 0);
+ dbcursor = NULL;
+#endif
+ set = dbiFreeIndexSet(set);
+ return DB_NOTFOUND;
+ }
+ set->count = j;
+
for (i = 0; i < set->count; i++)
set->recs[i].fpNum = fpNum;
@@ -3393,6 +3412,12 @@ static int skipDir(const char * dn)
int rpmdbFindFpList(rpmdb db, fingerPrint * fpList, dbiIndexSet * matchList,
int numItems)
{
+ return rpmdbFindFpListExclude(db, fpList, matchList, numItems, 0);
+}
+
+int rpmdbFindFpListExclude(rpmdb db, fingerPrint * fpList, dbiIndexSet * matchList,
+ int numItems, unsigned int exclude)
+{
DBT * key;
DBT * data;
HGE_t hge = (HGE_t)headerGetEntryMinMemory;
@@ -3424,10 +3449,13 @@ key->data = (void *) fpList[i].baseName;
key->size = strlen((char *)key->data);
if (key->size == 0) key->size++; /* XXX "/" fixup. */
- if (skipDir(fpList[i].entry->dirName))
+ /* HACK HACK HACK: don't skip dirs while removing
+ * packages as we will loose files on conflicts.
+ * exclude is not zero when removing */
+ if (!exclude && skipDir(fpList[i].entry->dirName))
continue;
- xx = rpmdbGrowIterator(mi, i);
+ xx = rpmdbGrowIterator(mi, i, exclude);
}