2011/11/2 Jeffrey Johnson <n3...@me.com>:
> xrealloc please so that there's no need to check NULL.
>
> empty statement semi-colons on next line as well. even better, move tmp++
> out of the for statement:
> for (i = 0; (tmp = strchr(tmp, '-')); i++, tmp++);
Will fix.
>
> There's no reason for advocacy/apology "hack" in comments either.
>
> Stating what is wrong (accessing multiple times, doing a headerlaod), or
> suggesting
> what could be done (changing the Nvra table to include additional
> tags concatenated) is perhaps clearer than making hand waving promises.
Agreed.
>
> All that's needed to solve this issue correctly is to commit to a
> string representation that is parsable usin a *RE when "optional" values
> like Epoch: and Distepoch:/Disttag: are there. You chose to add the pesky
> extra '-' to what had been previously devised … which forces
> additional input/output reformatting on retunred values. There are
> other representations that are unambigously parseable.
>
> Without a parseable string from which the tuple elements might be matched,
> well, rpm has
> *always* been doing secondary lookups from a primary key with
> a necessary headerLoad(). Its only the rpmdb access rewrite with "RPM ACID"
> that avoids the
> overhead of the headerLoad() (which was part of the measured 14.6x improvement
> in database lookups).
>
> The Nvra table conversion can be done in %postrans like
> rm -f /var/lib/rpm/Nvra
> rpm -q rpm > /dev/null
> You can easily check that cost any time you wish.
I know, but jI've just not made my way back to this one yet.. :|
>
>
> Hmmm … there's other code that starts to use this patch coming
> shortly, correct?
urpmi is depending on this, as it's using NVRA for package removal..
>
> hth
>
> 73 de Jeff
>
>
> On Nov 2, 2011, at 9:51 AM, Per Øyvind Karlsen wrote:
>
>> 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-...@rpm5.org
>
> ______________________________________________________________________
> RPM Package Manager http://rpm5.org
> Developer Communication List rpm-devel@rpm5.org
>
______________________________________________________________________
RPM Package Manager http://rpm5.org
Developer Communication List rpm-devel@rpm5.org