From: Panu Matilainen Date: Fri, 14 Sep 2012 05:41:01 +0000 (+0300) Subject: Change fpLookup() to return malloced memory (on first call) X-Git-Tag: tznext/4.11.0.1.tizen20130304~265 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e7adb8f14303edf0262744cea7a7f0a650f8ca2;p=tools%2Flibrpm-tizen.git Change fpLookup() to return malloced memory (on first call) - If the fingerprint pointer passed to it is NULL then allocate space for a new fingerprint, otherwise reuse the previous space. This should allow optimizing the case where repeatedly calling and directory doesn't change inside fpc so callers dont need special-case code for this. For now, we dont care about optimizations, other than making it possible later. --- diff --git a/lib/fprint.c b/lib/fprint.c index a31e546..a0aef4a 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -108,7 +108,7 @@ static const struct fprintCacheEntry_s * cacheContainsDirectory( return NULL; } -int fpLookup(fingerPrintCache cache, +static int doLookup(fingerPrintCache cache, const char * dirName, const char * baseName, int scareMemory, fingerPrint *fp) { @@ -230,6 +230,15 @@ exit: return 0; } +int fpLookup(fingerPrintCache cache, + const char * dirName, const char * baseName, int scareMemory, + fingerPrint **fp) +{ + if (*fp == NULL) + *fp = xcalloc(1, sizeof(**fp)); + return doLookup(cache, dirName, baseName, scareMemory, *fp); +} + /** * Return hash value for a finger print. * Hash based on dev and inode only! @@ -277,7 +286,7 @@ int fpLookupEquals(fingerPrintCache cache, fingerPrint *fp, const char * dirName, const char * baseName) { struct fingerPrint_s ofp; - fpLookup(cache, dirName, baseName, 1, &ofp); + doLookup(cache, dirName, baseName, 1, &ofp); return FP_EQUAL(*fp, ofp); } @@ -297,7 +306,7 @@ fingerPrint * fpLookupList(fingerPrintCache cache, rpmstrPool pool, fps[i].subDir = fps[i - 1].subDir; fps[i].baseName = rpmstrPoolStr(pool, baseNames[i]); } else { - fpLookup(cache, + doLookup(cache, rpmstrPoolStr(pool, dirNames[dirIndexes[i]]), rpmstrPoolStr(pool, baseNames[i]), 1, &fps[i]); @@ -364,7 +373,7 @@ static void fpLookupSubdir(rpmFpHash symlinks, fingerPrintCache fpc, rpmte p, in rstrscat(&link, endbasename+1, "/", NULL); } - fpLookup(fpc, link, fp->baseName, 0, fp); + doLookup(fpc, link, fp->baseName, 0, fp); free(link); free(currentsubdir); diff --git a/lib/fprint.h b/lib/fprint.h index 1486753..2a2b7cf 100644 --- a/lib/fprint.h +++ b/lib/fprint.h @@ -84,7 +84,7 @@ dev_t fpEntryDev(fingerPrintCache cache, fingerPrint *fp); RPM_GNUC_INTERNAL int fpLookup(fingerPrintCache cache, const char * dirName, const char * baseName, int scareMemory, - fingerPrint *fp); + fingerPrint **fp); /** * Compare two finger print entries. diff --git a/lib/rpmdb.c b/lib/rpmdb.c index a6600cd..22d2fe7 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -933,7 +933,7 @@ static int rpmdbFindByFile(rpmdb db, dbiIndex dbi, const char *filespec, char * dirName = NULL; const char * baseName; fingerPrintCache fpc = NULL; - fingerPrint fp1; + fingerPrint * fp1 = NULL; dbiIndexSet allMatches = NULL; unsigned int i; int rc = -2; /* assume error */ @@ -997,7 +997,7 @@ static int rpmdbFindByFile(rpmdb db, dbiIndex dbi, const char *filespec, if (!skip) { const char *dirName = dirNames[dirIndexes[num]]; - if (fpLookupEquals(fpc, &fp1, dirName, baseNames[num])) { + if (fpLookupEquals(fpc, fp1, dirName, baseNames[num])) { struct dbiIndexItem rec = { .hdrNum = dbiIndexRecordOffset(allMatches, i), .tagNum = dbiIndexRecordFileNumber(allMatches, i), @@ -1020,6 +1020,7 @@ static int rpmdbFindByFile(rpmdb db, dbiIndex dbi, const char *filespec, headerFree(h); } + free(fp1); fpCacheFree(fpc); if ((*matches)->count == 0) { diff --git a/lib/transaction.c b/lib/transaction.c index 8bcf5aa..1b00194 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -971,7 +971,7 @@ void checkInstalledFiles(rpmts ts, uint64_t fileCount, fingerPrintCache fpc) while (h != NULL) { headerGetFlags hgflags = HEADERGET_MINMEM; struct rpmtd_s bnames, dnames, dindexes, ostates; - fingerPrint fp, *fpp; + fingerPrint *fpp = NULL; unsigned int installedPkg; int beingRemoved = 0; rpmfi otherFi = NULL; @@ -1014,14 +1014,7 @@ void checkInstalledFiles(rpmts ts, uint64_t fileCount, fingerPrintCache fpc) dirName = rpmtdGetString(&dnames); baseName = rpmtdGetString(&bnames); - if (dirName == oldDir) { - /* directory is the same as last round */ - fp.baseName = baseName; - } else { - fpLookup(fpc, dirName, baseName, 1, &fp); - oldDir = dirName; - } - fpp = &fp; + fpLookup(fpc, dirName, baseName, 1, &fpp); } else { fpp = rpmfiFpsIndex(otherFi, fileNum); } @@ -1063,6 +1056,7 @@ void checkInstalledFiles(rpmts ts, uint64_t fileCount, fingerPrintCache fpc) rpmtdFreeData(&bnames); rpmtdFreeData(&dnames); rpmtdFreeData(&dindexes); + free(fpp); } headerFree(h); h = newheader;