First of two efforts at redefining how multiple packages for one name are

handled. This applies the patch from Gerald Teschl <gt@esi.ac.at> that makes a
multiple match yield the newest, rather than the first one encountered. After
this, I'll try to handle list-context.

CVS patchset: 5398
CVS date: 2002/04/12 00:16:33
This commit is contained in:
rjray 2002-04-12 00:16:33 +00:00
parent 2f1222755b
commit aaca0fed29
1 changed files with 17 additions and 3 deletions

View File

@ -5,7 +5,7 @@
#include <fcntl.h> #include <fcntl.h>
#include "RPM.h" #include "RPM.h"
static char * const rcsid = "$Id: Database.xs,v 1.16 2002/04/11 22:41:15 rjray Exp $"; static char * const rcsid = "$Id: Database.xs,v 1.17 2002/04/12 00:16:33 rjray Exp $";
/* /*
rpmdb_TIEHASH rpmdb_TIEHASH
@ -82,6 +82,7 @@ SV* rpmdb_FETCH(pTHX_ RPM__Database self, SV* key)
int namelen; /* Arg for SvPV(..., len) */ int namelen; /* Arg for SvPV(..., len) */
int offset; /* In case they pass an integer offset */ int offset; /* In case they pass an integer offset */
Header hdr; /* For rpmdbGetRecord() calls */ Header hdr; /* For rpmdbGetRecord() calls */
Header lasthdr; /* For searching latest rpm */
rpmdbMatchIterator mi; rpmdbMatchIterator mi;
SV** svp; SV** svp;
SV* FETCH; SV* FETCH;
@ -106,11 +107,24 @@ SV* rpmdb_FETCH(pTHX_ RPM__Database self, SV* key)
return newSVsv(*svp); return newSVsv(*svp);
offset = -1; offset = -1;
lasthdr = NULL;
mi = rpmdbInitIterator(dbstruct->dbp, RPMTAG_NAME, name, 0); mi = rpmdbInitIterator(dbstruct->dbp, RPMTAG_NAME, name, 0);
while ((hdr = rpmdbNextIterator(mi)) != NULL) while ((hdr = rpmdbNextIterator(mi)) != NULL)
{ {
offset = rpmdbGetIteratorOffset(mi); /* There might be more than one match. Find the newest one. */
break; if (lasthdr == NULL)
{
lasthdr = headerLink(hdr);
offset = rpmdbGetIteratorOffset(mi);
}
else
{
if (rpmVersionCompare(hdr, lasthdr) == 1)
{
lasthdr = headerLink(hdr);
offset = rpmdbGetIteratorOffset(mi);
}
}
} }
rpmdbFreeIterator(mi); rpmdbFreeIterator(mi);
if (offset == -1) if (offset == -1)