Add generalized iterator to rpmlib.

CVS patchset: 7482
CVS date: 2004/10/18 01:08:56
This commit is contained in:
jbj 2004-10-18 01:08:56 +00:00
parent ed4688aca7
commit e93a77c9b7
11 changed files with 88 additions and 46 deletions

View File

@ -20,7 +20,7 @@ EXTRA_PROGRAMS = tgi
pkgincdir = $(pkgincludedir)
pkginc_HEADERS = \
misc.h rpmcli.h rpmlib.h \
rpmal.h rpmds.h rpmfi.h rpmps.h rpmsx.h rpmte.h rpmts.h \
rpmal.h rpmds.h rpmfi.h rpmgi.h rpmps.h rpmsx.h rpmte.h rpmts.h \
stringbuf.h
noinst_HEADERS = \
cpio.h fsm.h manifest.h psm.h rpmlead.h signature.h rpmlock.h
@ -36,7 +36,7 @@ librpm_la_SOURCES = \
cpio.c depends.c formats.c fs.c fsm.c getdate.c \
manifest.c misc.c package.c \
poptALL.c poptI.c poptQV.c psm.c query.c \
rpmal.c rpmchecksig.c rpmds.c rpmfi.c rpminstall.c \
rpmal.c rpmchecksig.c rpmds.c rpmfi.c rpmgi.c rpminstall.c \
rpmlead.c rpmlibprov.c rpmps.c rpmrc.c rpmsx.c rpmte.c rpmts.c \
rpmvercmp.c signature.c stringbuf.c transaction.c \
verify.c rpmlock.c
@ -123,5 +123,5 @@ tplatform: tplatform.o librpm.la
trhn: trhn.o librpm.la
$(LINK) @LDFLAGS_STATIC@ $(CFLAGS) $(DEFS) $(INCLUDES) -o $@ $< $(mylibs)
tgi_SOURCES = tgi.c rpmgi.c
tgi_SOURCES = tgi.c
tgi_LDADD = librpm.la

View File

@ -316,8 +316,10 @@ int rpmtsAddInstallElement(rpmts ts, Header h,
if (rpmVersionCompare(h, oh))
#endif
xx = removePackage(ts, oh, rpmdbGetIteratorOffset(mi), pkgKey);
/*@-nullptrarith@*/
rpmMessage(RPMMESS_DEBUG, _(" Obsoletes: %s\t\terases %s\n"),
rpmdsDNEVR(obsoletes)+2, ohNEVRA);
/*@=nullptrarith@*/
ohNEVRA = _free(ohNEVRA);
}
}

View File

@ -6,6 +6,7 @@
#include <rpmio_internal.h>
#include <rpmlib.h>
#include <rpmmacro.h>
#include "stringbuf.h"
#include "manifest.h"
@ -65,7 +66,7 @@ char * rpmPermsString(int mode)
/**@todo Infinite loops through manifest files exist, operator error for now. */
/*@-boundsread@*/
int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
rpmRC rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
{
StringBuf sb = newStringBuf();
char * s = NULL;
@ -77,7 +78,7 @@ int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
/*@+voidabstract@*/
FILE * f = (FILE *) fdGetFp(fd);
/*@=voidabstract@*/
int rc = 0;
rpmRC rpmrc = RPMRC_OK;
int i;
/*@-boundswrite@*/
@ -105,7 +106,7 @@ int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
/* Insure that file contains only ASCII */
if (*s < 32) {
rc = 1;
rpmrc = RPMRC_NOTFOUND;
goto exit;
}
@ -121,13 +122,13 @@ int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
/*@=branchstate@*/
if (!(s && *s)) {
rc = 1;
rpmrc = RPMRC_NOTFOUND;
goto exit;
}
/* Glob manifest items. */
rc = rpmGlob(s, &ac, &av);
if (rc) goto exit;
rpmrc = rpmGlob(s, &ac, &av);
if (rpmrc != RPMRC_OK) goto exit;
/* Find 1st existing unprocessed arg. */
for (i = 0; i < argc; i++)
@ -162,7 +163,7 @@ int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
exit:
/*@-branchstate@*/
if (argvPtr == NULL || (rc != 0 && av)) {
if (argvPtr == NULL || (rpmrc != RPMRC_OK && av)) {
if (av)
/*@-boundswrite@*/
for (i = 0; i < ac; i++)
@ -173,7 +174,7 @@ exit:
/*@=branchstate@*/
sb = freeStringBuf(sb);
/*@-nullstate@*/ /* FIX: *argvPtr may be NULL. */
return rc;
return rpmrc;
/*@=nullstate@*/
}
/*@=boundsread@*/

View File

@ -24,11 +24,12 @@ char * rpmPermsString(int mode)
/**
* Read manifest, glob items, and append to existing args.
* @param fd manifest file handle
* @retval argcPtr no. of args
* @retval argvPtr args themselves
* @param fd manifest file handle
* @retval argcPtr no. of args
* @retval argvPtr args themselves
* @return RPMRC_OK on success
*/
int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
rpmRC rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
/*@globals fileSystem, internalState @*/
/*@modifies fd, *argcPtr, *argvPtr, fileSystem, internalState @*/;

View File

@ -868,9 +868,11 @@ rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char * fn, Header * hdrp)
/* XXX repackaged packages have appended tags, legacy dig/sig check fails */
if (opx > 0)
(void) rpmswEnter(rpmtsOp(ts, opx), 0);
/*@-type@*/ /* XXX arrow access of non-pointer (FDSTAT_t) */
nb = -fd->stats->ops[FDSTAT_READ].bytes;
rc = rpmReadHeader(ts, fd, &h, &msg);
nb += fd->stats->ops[FDSTAT_READ].bytes;
/*@=type@*/
if (opx > 0)
(void) rpmswExit(rpmtsOp(ts, opx), nb);

View File

@ -258,6 +258,8 @@ struct rpmQVKArguments_s {
rpmfileAttrs qva_fflags; /*!< Bit(s) to filter on attribute. */
/*@only@*/ /*@null@*/
rpmdbMatchIterator qva_mi; /*!< Match iterator on selected headers. */
/*@refccounted@*/ /*@null@*/
rpmdbMatchIterator qva_gi; /*!< Generalized iterator on selected headers. */
/*@null@*/
QVF_t qva_showPackage; /*!< Function to display iterator matches. */
/*@null@*/

View File

@ -12,9 +12,12 @@
#include "debug.h"
/*@access rpmdbMatchIterator @*/
/*@unchecked@*/
int _rpmgi_debug = 0;
/*@unchecked@*/ /*@observer@*/
static const char * hdlistpath = "/usr/share/comps/i386/hdlist";
rpmgi XrpmgiUnlink(rpmgi gi, const char * msg, const char * fn, unsigned ln)
@ -52,6 +55,7 @@ fprintf(stderr, "*** gi %p\t%p[%d]\n", gi, gi->argv, gi->argc);
(void) rpmgiUnlink(gi, NULL);
/*@-usereleased@*/
switch (gi->tag) {
default:
case RPMGI_RPMDB:
@ -80,7 +84,10 @@ fprintf(stderr, "*** gi %p\t%p[%d]\n", gi, gi->argv, gi->argc);
gi->ts = rpmtsFree(gi->ts);
memset(gi, 0, sizeof(*gi)); /* XXX trash and burn */
/*@-refcounttrans@*/
gi = _free(gi);
/*@=refcounttrans@*/
/*@=usereleased@*/
return NULL;
}
@ -94,6 +101,9 @@ rpmgi rpmgiNew(rpmts ts, int tag, void *const keyp, size_t keylen)
gi->ts = rpmtsLink(ts, NULL);
gi->tag = tag;
gi->i = -1;
gi->fd = NULL;
gi->argv = NULL;
gi->argc = 0;
switch (gi->tag) {
default:
@ -109,7 +119,7 @@ fprintf(stderr, "*** gi %p\t%p\n", gi, gi->mi);
break;
case RPMGI_ARGLIST:
case RPMGI_FTSWALK:
{ ARGV_t pav = keyp;
{ ARGV_t pav = keyp;
const char * arg;
unsigned flags = keylen;
int xx;
@ -139,8 +149,10 @@ fprintf(stderr, "*** gi %p\t%p[%d]\n", gi, gi->argv, gi->argc);
return gi;
}
/*@unchecked@*/
static int indent = 2;
/*@unchecked@*/ /*@observer@*/
static const char * ftsInfoStrings[] = {
"UNKNOWN",
"D",
@ -159,16 +171,22 @@ static const char * ftsInfoStrings[] = {
"W",
};
static const char * ftsInfoStr(int fts_info) {
/*@observer@*/
static const char * ftsInfoStr(int fts_info)
/*@*/
{
if (!(fts_info >= 1 && fts_info <= 14))
fts_info = 0;
/*@-compmempass@*/
return ftsInfoStrings[ fts_info ];
/*@=compmempass@*/
}
/*@only@*/
static const char * rpmgiPathOrQF(rpmgi gi, const char * fn,
static const char * rpmgiPathOrQF(const rpmgi gi, const char * fn,
/*@null@*/ Header * hdrp)
/*@modifies gi, *hdrp @*/
/*@modifies *hdrp @*/
{
const char * fmt = ((gi->queryFormat != NULL)
? gi->queryFormat : "%{name}-%{version}-%{release}");
@ -189,8 +207,9 @@ static const char * rpmgiPathOrQF(rpmgi gi, const char * fn,
}
/*@null@*/
static rpmRC rpmgiReadManifest(rpmgi gi, const char * fileURL)
/*@*/
static rpmRC rpmgiLoadManifest(rpmgi gi, const char * fileURL)
/*@globals h_errno, internalState @*/
/*@modifies gi, h_errno, internalState @*/
{
rpmRC rpmrc;
FD_t fd;
@ -212,7 +231,8 @@ static rpmRC rpmgiReadManifest(rpmgi gi, const char * fileURL)
/*@null@*/
static Header rpmgiReadHeader(rpmgi gi, const char * fileURL)
/*@*/
/*@globals rpmGlobalMacroContext, h_errno, internalState @*/
/*@modifies gi, rpmGlobalMacroContext, h_errno, internalState @*/
{
Header h = NULL;
rpmRC rpmrc;
@ -247,7 +267,6 @@ static Header rpmgiReadHeader(rpmgi gi, const char * fileURL)
}
const char * rpmgiNext(/*@null@*/ rpmgi gi)
/*@modifies gi @*/
{
const char * val = NULL;
const char * fn = NULL;
@ -259,15 +278,18 @@ const char * rpmgiNext(/*@null@*/ rpmgi gi)
default:
case RPMGI_RPMDB:
h = rpmdbNextIterator(gi->mi);
/*@-branchstate@*/
if (h != NULL) {
val = rpmgiPathOrQF(gi, "rpmdb", &h);
} else {
gi->mi = rpmdbFreeIterator(gi->mi);
gi->i = -1;
}
/*@=branchstate@*/
break;
case RPMGI_HDLIST:
h = headerRead(gi->fd, HEADER_MAGIC_YES);
/*@-branchstate@*/
if (h != NULL) {
val = rpmgiPathOrQF(gi, "hdlist", &h);
} else {
@ -275,8 +297,10 @@ const char * rpmgiNext(/*@null@*/ rpmgi gi)
gi->fd = NULL;
gi->i = -1;
}
/*@=branchstate@*/
break;
case RPMGI_ARGLIST:
/*@-branchstate@*/
if (gi->argv != NULL && gi->argv[gi->i] != NULL) {
if (_rpmgi_debug < 0)
fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i]);
@ -285,21 +309,24 @@ fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i])
fn = gi->argv[gi->i];
h = rpmgiReadHeader(gi, fn);
if (h != NULL)
break;
/*@loopbreak@*/ break;
/* Not a header, so try for a manifest. */
gi->argv[gi->i] = NULL;
rpmrc = rpmgiReadManifest(gi, fn);
rpmrc = rpmgiLoadManifest(gi, fn);
if (rpmrc != RPMRC_OK) {
gi->argv[gi->i] = fn;
break;
/*@loopbreak@*/ break;
}
fn = _free(fn);
} while (1);
/* XXX check rpmrc */
/*@-compdef@*/ /* XXX WTF? gi->argv undefined */
val = rpmgiPathOrQF(gi, fn, &h);
/*@=compdef@*/
h = headerFree(h);
} else
gi->i = -1;
/*@=branchstate@*/
break;
case RPMGI_FTSWALK:
if (gi->argv == NULL)
@ -318,6 +345,7 @@ fprintf(stderr, "FTS_%s\t%*s %s\n", ftsInfoStr(fts->fts_info),
indent * (fts->fts_level < 0 ? 0 : fts->fts_level), "",
fts->fts_name);
/*@-branchstate@*/
switch (fts->fts_info) {
case FTS_F:
case FTS_SL:
@ -327,10 +355,11 @@ fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->ftsp, gi->i, fts->fts_path);
h = rpmgiReadHeader(gi, fn);
val = rpmgiPathOrQF(gi, fn, &h);
h = headerFree(h);
break;
/*@switchbreak@*/ break;
default:
break;
/*@switchbreak@*/ break;
}
/*@=branchstate@*/
}
if (gi->fts == NULL && gi->ftsp != NULL) {
int xx;

View File

@ -17,10 +17,6 @@
extern int _rpmgi_debug;
/*@=exportlocal@*/
/**
*/
typedef /*@abstract@*/ struct rpmgi_s * rpmgi;
/**
*/
typedef enum rpmgiTag_e {
@ -38,23 +34,19 @@ struct rpmgi_s {
rpmts ts;
int tag;
int i;
const char * queryFormat;
/*@dependent@*/
/*@relnull@*/
rpmdbMatchIterator mi;
/*@refcounted@*/
FD_t fd;
/*@only@*/
const char * queryFormat;
/*@dependent@*/
ARGV_t argv;
int argc;
int ftsOpts;
/*@dependent@*/
FTS * ftsp;
/*@dependent@*/
FTSENT * fts;
/*@refs@*/
@ -107,21 +99,29 @@ rpmgi XrpmgiLink (/*@null@*/ rpmgi gi, /*@null@*/ const char * msg,
* @param gi generalized iterator
* @return NULL always
*/
/*@only@*/
/*@null@*/
rpmgi rpmgiFree(/*@killref@*/ /*@only@*/ /*@null@*/ rpmgi gi)
/*@modifies gi @*/;
/*@globals rpmGlobalMacroContext, h_errno, internalState @*/
/*@modifies gi, rpmGlobalMacroContext, h_errno, internalState @*/;
/** Create a generalized iterator.
* @param argv iterator argv array
* @param flags iterator flags
* @return new general iterator
*/
/*@only@*/
/*@null@*/
rpmgi rpmgiNew(rpmts ts, int tag, void *const keyp, size_t keylen)
/*@*/;
/*@globals rpmGlobalMacroContext, h_errno, internalState @*/
/*@modifies ts, rpmGlobalMacroContext, h_errno, internalState @*/;
/** Return next iteration element.
* @param gi generalized iterator
* @returns next element
*/
/*@observer@*/
const char * rpmgiNext(/*@null@*/ rpmgi gi)
/*@modifies gi @*/;
/*@globals rpmGlobalMacroContext, h_errno, internalState @*/
/*@modifies gi, rpmGlobalMacroContext, h_errno, internalState @*/;
int rpmgiSetQueryFormat(rpmgi gi, const char * queryFormat)
/*@modifies gi @*/;

View File

@ -112,6 +112,11 @@ typedef /*@abstract@*/ /*@refcounted@*/ struct rpmdb_s * rpmdb;
*/
typedef /*@abstract@*/ struct _rpmdbMatchIterator * rpmdbMatchIterator;
/** \ingroup rpmcli
* Generalized iterator.
*/
typedef /*@abstract@*/ /*@refcounted@*/ struct rpmgi_s * rpmgi;
/** \ingroup header
* Return name, version, release strings from header.
* @param h header

View File

@ -993,7 +993,7 @@ uint_32 rpmtsSetColor(rpmts ts, uint_32 color)
* @param opx operation timestamp index
* @return pointer to operation timestamp.
*/
/*@null@*/
/*@relnull@*/
rpmop rpmtsOp(rpmts ts, rpmtsOpX opx)
/*@*/;

View File

@ -699,7 +699,7 @@ int rpmdbCheckSignals(void)
rpmdb db;
rpmdbMatchIterator mi;
rpmMessage(RPMMESS_NORMAL, "Exiting on signal(0x%lx) ...\n", *((unsigned long *)&rpmsqCaught));
rpmMessage(RPMMESS_DEBUG, "Exiting on signal(0x%lx) ...\n", *((unsigned long *)&rpmsqCaught));
/*@-branchstate@*/
while ((mi = rpmmiRock) != NULL) {