* @param db rpm database
* @param dbi index database handle (always RPMDBI_BASENAMES)
* @param filespec
+ * @param usestate take file state into account?
* @retval matches
* @return 0 on success, 1 on not found, -2 on error
*/
static int rpmdbFindByFile(rpmdb db, dbiIndex dbi, const char *filespec,
- dbiIndexSet * matches)
+ int usestate, dbiIndexSet * matches)
{
char * dirName = NULL;
const char * baseName;
i = 0;
while (i < allMatches->count) {
- struct rpmtd_s bn, dn, di;
+ struct rpmtd_s bn, dn, di, fs;
const char ** baseNames, ** dirNames;
uint32_t * dirIndexes;
unsigned int offset = dbiIndexRecordOffset(allMatches, i);
baseNames = bn.data;
dirNames = dn.data;
dirIndexes = di.data;
+ if (usestate)
+ headerGet(h, RPMTAG_FILESTATES, &fs, HEADERGET_MINMEM);
do {
fingerPrint fp2;
int num = dbiIndexRecordFileNumber(allMatches, i);
+ int skip = 0;
- fp2 = fpLookup(fpc, dirNames[dirIndexes[num]], baseNames[num], 1);
- if (FP_EQUAL(fp1, fp2)) {
- struct dbiIndexItem rec = {
- .hdrNum = dbiIndexRecordOffset(allMatches, i),
- .tagNum = dbiIndexRecordFileNumber(allMatches, i),
- };
- dbiAppendSet(*matches, &rec, 1, sizeof(rec), 0);
+ if (usestate) {
+ rpmtdSetIndex(&fs, num);
+ int s = rpmtdGetNumber(&fs);
+ if (s != RPMFILE_STATE_NORMAL && s != RPMFILE_STATE_NETSHARED) {
+ skip = 1;
+ }
+ }
+
+ if (!skip) {
+ fp2 = fpLookup(fpc, dirNames[dirIndexes[num]],
+ baseNames[num], 1);
+ if (FP_EQUAL(fp1, fp2)) {
+ struct dbiIndexItem rec = {
+ .hdrNum = dbiIndexRecordOffset(allMatches, i),
+ .tagNum = dbiIndexRecordFileNumber(allMatches, i),
+ };
+ dbiAppendSet(*matches, &rec, 1, sizeof(rec), 0);
+ }
}
prevoff = offset;
rpmtdFreeData(&bn);
rpmtdFreeData(&dn);
rpmtdFreeData(&di);
+ if (usestate)
+ rpmtdFreeData(&fs);
headerFree(h);
}
/* Fixup the physical index for our pseudo indexes */
if (rpmtag == RPMDBI_LABEL) {
dbtag = RPMDBI_NAME;
+ } else if (rpmtag == RPMDBI_INSTFILENAMES) {
+ dbtag = RPMDBI_BASENAMES;
}
dbi = rpmdbOpenIndex(db, dbtag, 0);
if (rpmtag == RPMDBI_LABEL) {
rc = dbiFindByLabel(db, dbi, keyp, &set);
} else if (rpmtag == RPMDBI_BASENAMES) {
- rc = rpmdbFindByFile(db, dbi, keyp, &set);
+ rc = rpmdbFindByFile(db, dbi, keyp, 0, &set);
+ } else if (rpmtag == RPMDBI_INSTFILENAMES) {
+ rc = rpmdbFindByFile(db, dbi, keyp, 1, &set);
} else {
rc = dbiGetToSet(dbi, keyp, keylen, &set);
}