RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Per Øyvind Karlsen Root: /v/rpm/cvs Email: pkarl...@rpm5.org Module: rpm Date: 02-Nov-2011 14:51:38 Branch: rpm-5_4 Handle: 2011110213513800 Modified files: (Branch: rpm-5_4) rpm/rpmdb rpmdb.c Log: add disttag/distepoch matching hack forgotten on rpm-5_3 Summary: Revision Changes Path 1.392.2.8 +85 -0 rpm/rpmdb/rpmdb.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/rpmdb/rpmdb.c ============================================================================ $ cvs diff -u -r1.392.2.7 -r1.392.2.8 rpmdb.c --- rpm/rpmdb/rpmdb.c 5 Sep 2011 23:49:41 -0000 1.392.2.7 +++ rpm/rpmdb/rpmdb.c 2 Nov 2011 13:51:38 -0000 1.392.2.8 @@ -2448,6 +2448,91 @@ rpmRC rc; rc = dbiFindMatches(dbi, keyp, &set); +#if defined(RPM_VENDOR_MANDRIVA) + /* + * Hack to workaround disttag/distepoch pattern matching issue to buy some + * time to come up with better pattern fix.. + * One size should fit all now.. ;) + * + * This patch will try match NVR first, then for all matches returned, + * it will match disttag, distepoch & arch individually. + */ + + /* We'll only try this if query fails */ + if(!rc && ((const char*)keyp)[0] != '^' && tag == RPMTAG_NVRA && + (set == NULL || set->count < 1)) { + size_t i; + char *tmp = (char*)keyp; + + /* If pattern has less than three '-', it can't contain disttag, so + * no point in trying */ + for (i = 0; (tmp = strchr(tmp, '-')); i++, tmp++); + if (i >= 3) { + dbiIndex pdbi; + DBC *pdbc; + const char *origkeyp = keyp; + size_t klen = strlen(keyp)+1; + size_t size = 0; + int xx; + + keyp = alloca(klen); + stpcpy((char*)keyp, origkeyp); + tmp = strrchr(keyp, '-'); + *tmp = '\0'; + rc = dbiFindMatches(dbi, keyp, &set); + + pdbi = dbiOpen(db, RPMDBI_PACKAGES, 0); + xx = dbiCopen(pdbi, dbiTxnid(pdbi), &pdbc, 0); + + for(i = 0; set && i < set->count; i++) { + DBT k = DBT_INIT; + DBT v = DBT_INIT; + Header h; + uint32_t offset = _hton_ui(set->recs[i].hdrNum); + rpmTag checkTags[] = + { RPMTAG_DISTTAG, RPMTAG_DISTEPOCH, RPMTAG_ARCH }; + int j; + + memset(&k, 0, sizeof(k)); + memset(&v, 0, sizeof(v)); + k.data = &offset; + k.size = sizeof(offset); + + xx = dbiGet(dbi, pdbc, &k, &v, DB_SET); + h = headerLoad(v.data); + tmp = (char*)((size_t)keyp + strlen(keyp) + 1); + + for (j = 0; j < (int)(sizeof(checkTags)/sizeof(checkTags[0])) && + *tmp != '\0'; j++) { + he->tag = checkTags[j]; + if(headerGet(h, he, 0)) { + size_t len = strlen(he->p.str); + + if (he->tag == RPMTAG_ARCH && *tmp == '.') + tmp++; + + if(!strncmp(he->p.str, tmp, len)) + tmp += len; + _free(he->p.ptr); + } + } + if(j && *tmp == '\0') { + set->recs[size].hdrNum = set->recs[i].hdrNum; + set->recs[size].tagNum = set->recs[i].tagNum; + size++; + } + + h = headerFree(h); + } + if(set && set->count != size) { + set->count = size; + set->recs = realloc(set->recs, size * sizeof(*set->recs)); + } + + xx = dbiCclose(pdbi, pdbc, 0); + } + } +#endif if ((rc && rc != RPMRC_NOTFOUND) || set == NULL || set->count < 1) { /* error or empty set */ set = dbiFreeIndexSet(set); @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org