summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2004-10-24 19:36:30 +0000
committerjbj <devnull@localhost>2004-10-24 19:36:30 +0000
commit3691d13f0427ecee102acfc2a658c6c2a89227fb (patch)
treec243ec4e55c8bbe1d17552b90e2681583ede5939
parent883580417100b31808d0ef8d69bcfdd510e85d0a (diff)
downloadrpm-3691d13f0427ecee102acfc2a658c6c2a89227fb.tar.gz
rpm-3691d13f0427ecee102acfc2a658c6c2a89227fb.tar.bz2
rpm-3691d13f0427ecee102acfc2a658c6c2a89227fb.zip
Explicit rpmgiFlags enum defined, add RPMGI_{NOGLOB,NOMANIFEST,NOHEADER}.
Abstract arg iteration into rpmcliArgIter(). Add undocumented --rpmgidebug. CVS patchset: 7504 CVS date: 2004/10/24 19:36:30
-rw-r--r--lib/poptALL.c5
-rw-r--r--lib/query.c48
-rw-r--r--lib/rpmcli.h18
-rw-r--r--lib/rpmgi.c55
-rw-r--r--lib/rpmgi.h17
-rw-r--r--lib/tgi.c28
-rw-r--r--lib/verify.c14
7 files changed, 129 insertions, 56 deletions
diff --git a/lib/poptALL.c b/lib/poptALL.c
index 0f7190967..ed1ef1fc6 100644
--- a/lib/poptALL.c
+++ b/lib/poptALL.c
@@ -62,6 +62,9 @@ extern int _rpmds_debug;
extern int _rpmfi_debug;
/*@unchecked@*/
+extern int _rpmgi_debug;
+
+/*@unchecked@*/
extern int _rpmps_debug;
/*@unchecked@*/
@@ -312,6 +315,8 @@ struct poptOption rpmcliAllPoptTable[] = {
NULL, NULL},
{ "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
NULL, NULL},
+ { "rpmgidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
+ NULL, NULL},
{ "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
N_("debug rpmio I/O"), NULL},
{ "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
diff --git a/lib/query.c b/lib/query.c
index d16bd6b8e..83a429c70 100644
--- a/lib/query.c
+++ b/lib/query.c
@@ -15,6 +15,7 @@
#include "rpmdb.h"
#include "rpmfi.h"
+#include "rpmgi.h"
#include "rpmts.h"
#include "manifest.h"
@@ -781,9 +782,40 @@ restart:
}
/*@=bounds@*/
-int rpmcliQuery(rpmts ts, QVA_t qva, const char ** argv)
+int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_t argv)
{
const char * arg;
+ int ftsOpts = 0;
+ rpmgiFlags giflags = RPMGI_NOGLOB;
+ int ec = 0;
+
+ qva->qva_gi = rpmgiNew(ts, RPMDBI_ARGLIST, NULL, 0);
+ qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, giflags);
+
+ switch (qva->qva_source) {
+ case RPMQV_ALL:
+ /*@-nullpass@*/ /* FIX: argv can be NULL, cast to pass argv array */
+ ec = rpmQueryVerify(qva, ts, (const char *) argv);
+ /*@=nullpass@*/
+ break;
+ default:
+/*@-boundsread@*/
+ if (argv != NULL)
+ while ((arg = *argv++) != NULL) {
+ ec += rpmQueryVerify(qva, ts, arg);
+ rpmtsEmpty(ts);
+ }
+/*@=boundsread@*/
+ break;
+ }
+
+ qva->qva_gi = rpmgiFree(qva->qva_gi);
+
+ return ec;
+}
+
+int rpmcliQuery(rpmts ts, QVA_t qva, const char ** argv)
+{
rpmVSFlags vsflags, ovsflags;
int ec = 0;
@@ -824,19 +856,7 @@ int rpmcliQuery(rpmts ts, QVA_t qva, const char ** argv)
#endif
ovsflags = rpmtsSetVSFlags(ts, vsflags);
- if (qva->qva_source == RPMQV_ALL) {
- /*@-nullpass@*/ /* FIX: argv can be NULL, cast to pass argv array */
- ec = rpmQueryVerify(qva, ts, (const char *) argv);
- /*@=nullpass@*/
- } else {
-/*@-boundsread@*/
- if (argv != NULL)
- while ((arg = *argv++) != NULL) {
- ec += rpmQueryVerify(qva, ts, arg);
- rpmtsEmpty(ts);
- }
-/*@=boundsread@*/
- }
+ ec = rpmcliArgIter(ts, qva, argv);
vsflags = rpmtsSetVSFlags(ts, ovsflags);
if (qva->qva_showPackage == showQueryPackage)
diff --git a/lib/rpmcli.h b/lib/rpmcli.h
index d5907137f..89519059c 100644
--- a/lib/rpmcli.h
+++ b/lib/rpmcli.h
@@ -8,6 +8,7 @@
#include "rpmlib.h"
#include "rpmurl.h"
#include "rpmmacro.h"
+#include "argv.h"
/** \ingroup rpmcli
* Should version 3 packages be produced?
@@ -259,7 +260,9 @@ struct rpmQVKArguments_s {
/*@only@*/ /*@null@*/
rpmdbMatchIterator qva_mi; /*!< Match iterator on selected headers. */
/*@refccounted@*/ /*@null@*/
- rpmdbMatchIterator qva_gi; /*!< Generalized iterator on selected headers. */
+ rpmgi qva_gi; /*!< Generalized iterator on args. */
+ rpmRC qva_rc; /*!< Current return code. */
+
/*@null@*/
QVF_t qva_showPackage; /*!< Function to display iterator matches. */
/*@null@*/
@@ -365,6 +368,19 @@ int showQueryPackage(QVA_t qva, rpmts ts, Header h)
/*@modifies ts, h, rpmGlobalMacroContext, fileSystem, internalState @*/;
/** \ingroup rpmcli
+ * Iterate over query/verify arg list.
+ * @param ts transaction set
+ * @param qva parsed query/verify options
+ * @param argv query argument(s) (or NULL)
+ * @return 0 on success, else no. of failures
+ */
+int rpmcliArgIter(rpmts ts, QVA_t qva, /*@null@*/ ARGV_t argv)
+ /*@globals rpmGlobalMacroContext, h_errno,
+ fileSystem, internalState @*/
+ /*@modifies ts, qva, rpmGlobalMacroContext,
+ fileSystem, internalState @*/;
+
+/** \ingroup rpmcli
* Display package information.
* @todo hack: RPMQV_ALL can pass char ** arglist = NULL, not char * arg. Union?
* @param ts transaction set
diff --git a/lib/rpmgi.c b/lib/rpmgi.c
index f958f368f..5b429e552 100644
--- a/lib/rpmgi.c
+++ b/lib/rpmgi.c
@@ -151,11 +151,14 @@ static rpmRC rpmgiLoadReadHeader(rpmgi gi)
fn = gi->argv[gi->i];
h = rpmgiReadHeader(gi, fn);
- if (h != NULL) {
+ if (h != NULL || (gi->flags & RPMGI_NOHEADER)) {
rpmrc = RPMRC_OK;
break;
}
+ if (gi->flags & RPMGI_NOMANIFEST)
+ break;
+
/* Not a header, so try for a manifest. */
gi->argv[gi->i] = NULL; /* HACK */
rpmrc = rpmgiLoadManifest(gi, fn);
@@ -166,7 +169,7 @@ static rpmRC rpmgiLoadReadHeader(rpmgi gi)
fn = _free(fn);
} while (1);
- if (rpmrc == RPMRC_OK && h != NULL)
+ if (rpmrc == RPMRC_OK && h != NULL && !(gi->flags & RPMGI_NOHEADER))
gi->h = headerLink(h);
h = headerFree(h);
@@ -185,6 +188,7 @@ static rpmRC rpmgiWalkReadHeader(rpmgi gi)
{
rpmRC rpmrc = RPMRC_NOTFOUND;
Header h = NULL;
+ int bingo = 0;
if (gi->ftsp != NULL)
while ((gi->fts = Fts_read(gi->ftsp)) != NULL) {
@@ -201,13 +205,15 @@ fprintf(stderr, "FTS_%s\t%*s %s\n", ftsInfoStr(fts->fts_info),
case FTS_SL:
if (_rpmgi_debug < 0)
fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->ftsp, gi->i, fts->fts_path);
- h = rpmgiReadHeader(gi, fts->fts_path);
+ bingo = 1;
/*@switchbreak@*/ break;
default:
/*@switchbreak@*/ break;
}
/*@=branchstate@*/
- if (h != NULL) {
+ if (bingo) {
+ if (!(gi->flags & RPMGI_NOHEADER))
+ h = rpmgiReadHeader(gi, fts->fts_path);
rpmrc = RPMRC_OK;
break;
}
@@ -232,12 +238,20 @@ static rpmRC rpmgiGlobArgv(rpmgi gi, ARGV_t argv)
{
const char * arg;
rpmRC rpmrc = RPMRC_OK;
+ int ac = 0;
+ int xx;
+
+ if (gi->flags & RPMGI_NOGLOB) {
+ while (argv[ac] != NULL)
+ ac++;
+ xx = argvAppend(&gi->argv, argv);
+ gi->argc = ac;
+ return rpmrc;
+ }
if (argv != NULL)
while ((arg = *argv++) != NULL) {
ARGV_t av = NULL;
- int ac = 0;
- int xx;
xx = rpmGlob(arg, &ac, &av);
xx = argvAppend(&gi->argv, av);
@@ -370,11 +384,14 @@ fprintf(stderr, "*** gi %p\t%p\n", gi, gi->mi);
if (gi->mi != NULL) { /* XXX unnecessary */
Header h = rpmdbNextIterator(gi->mi);
if (h != NULL) {
- gi->h = headerLink(h);
+ if (!(gi->flags & RPMGI_NOHEADER))
+ gi->h = headerLink(h);
sprintf(hnum, "%u", rpmdbGetIteratorOffset(gi->mi));
+ rpmrc = RPMRC_OK;
+ /* XXX header reference held by iterator, so no headerFree */
}
}
- if (gi->h == NULL) {
+ if (rpmrc != RPMRC_OK) {
gi->mi = rpmdbFreeIterator(gi->mi);
goto enditer;
}
@@ -387,11 +404,15 @@ fprintf(stderr, "*** gi %p\t%p\n", gi, gi->mi);
gi->active = 1;
}
if (gi->fd != NULL) {
- gi->h = headerRead(gi->fd, HEADER_MAGIC_YES);
+ Header h = headerRead(gi->fd, HEADER_MAGIC_YES);
+ if (h != NULL && !(gi->flags & RPMGI_NOHEADER))
+ gi->h = headerLink(h);
sprintf(hnum, "%u", (unsigned)gi->i);
+ rpmrc = RPMRC_OK;
+ h = headerFree(h);
}
- if (gi->h == NULL) {
+ if (rpmrc != RPMRC_OK) {
if (gi->fd != NULL) (void) Fclose(gi->fd);
gi->fd = NULL;
goto enditer;
@@ -425,7 +446,7 @@ fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i])
/* Read next header, lazily walking file tree. */
rpmrc = rpmgiWalkReadHeader(gi);
- if (gi->h == NULL || rpmrc != RPMRC_OK) {
+ if (rpmrc != RPMRC_OK) {
xx = Fts_close(gi->ftsp);
gi->ftsp = NULL;
goto enditer;
@@ -437,15 +458,14 @@ fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i])
}
/*@=branchstate@*/
- if (gi->flags & 0x1) {
+ if ((gi->flags & RPMGI_TSADD) && gi->h != NULL) {
xx = rpmtsAddInstallElement(gi->ts, gi->h, (fnpyKey)gi->hdrPath, 0, NULL);
- /* TODO save header and path in rpmte. */
}
- return RPMRC_OK;
+ return rpmrc;
enditer:
- if (gi->flags & 0x2) {
+ if (gi->flags & RPMGI_TSORDER) {
xx = rpmtsCheck(gi->ts);
xx = rpmtsOrder(gi->ts);
}
@@ -475,12 +495,11 @@ rpmts rpmgiTs(rpmgi gi)
/*@=compdef =refcounttrans =retexpose =usereleased@*/
}
-rpmRC rpmgiSetArgs(rpmgi gi, ARGV_t argv, int ftsOpts, int flags)
+rpmRC rpmgiSetArgs(rpmgi gi, ARGV_t argv, int ftsOpts, rpmgiFlags flags)
{
- rpmRC rpmrc = rpmgiGlobArgv(gi, argv);
gi->ftsOpts = ftsOpts;
gi->flags = flags;
- return rpmrc;
+ return rpmgiGlobArgv(gi, argv);
}
/*@=modfilesys@*/
diff --git a/lib/rpmgi.h b/lib/rpmgi.h
index ac883dbd0..c1ebcb118 100644
--- a/lib/rpmgi.h
+++ b/lib/rpmgi.h
@@ -17,6 +17,16 @@
extern int _rpmgi_debug;
/*@=exportlocal@*/
+/**
+ */
+typedef enum rpmgiFlags_e {
+ RPMGI_TSADD = (1 << 0),
+ RPMGI_TSORDER = (1 << 1),
+ RPMGI_NOGLOB = (1 << 2),
+ RPMGI_NOMANIFEST = (1 << 3),
+ RPMGI_NOHEADER = (1 << 4)
+} rpmgiFlags;
+
#if defined(_RPMGI_INTERNAL)
/** \ingroup rpmio
*/
@@ -27,7 +37,7 @@ struct rpmgi_s {
const void * keyp; /*!< Iterator key. */
size_t keylen; /*!< Iterator key length. */
- int flags; /*!< Iterator control bits. */
+ rpmgiFlags flags; /*!< Iterator control bits. */
int active; /*!< Iterator is active? */
int i; /*!< Element index. */
/*@null@*/
@@ -157,11 +167,12 @@ rpmts rpmgiTs(/*@null@*/ rpmgi gi)
/**
* Load iterator args.
* @param gi generalized iterator
+ * @param argv arg list
* @param ftsOpts fts(3) flags
* @param flags iterator flags
- * @returns RPMRC_OK
+ * @returns RPMRC_OK on success
*/
-rpmRC rpmgiSetArgs(rpmgi gi, ARGV_t, int ftsOpts, int flags)
+rpmRC rpmgiSetArgs(rpmgi gi, ARGV_t argv, int ftsOpts, rpmgiFlags flags)
/*@modifies gi @*/;
#ifdef __cplusplus
diff --git a/lib/tgi.c b/lib/tgi.c
index e7c84df9e..cb78e09c5 100644
--- a/lib/tgi.c
+++ b/lib/tgi.c
@@ -15,17 +15,19 @@
static const char * gitagstr = "packages";
static const char * gikeystr = NULL;
static rpmtransFlags transFlags = 0;
-static int giflags = 0x3;
+static rpmgiFlags giflags = 0;
static int ftsOpts = 0;
static const char * queryFormat = NULL;
+static const char * defaultQueryFormat =
+ "%{name}-%{version}-%{release}.%|SOURCERPM?{%{arch}.rpm}:{%|ARCH?{src.rpm}:{pubkey}|}|";
/*@only@*/ /*@null@*/
static const char * rpmgiPathOrQF(const rpmgi gi)
/*@*/
{
const char * fmt = ((queryFormat != NULL)
- ? queryFormat : "%{name}-%{version}-%{release}.%{arch}");
+ ? queryFormat : defaultQueryFormat);
const char * val = NULL;
Header h = rpmgiHeader(gi);
@@ -52,6 +54,17 @@ static struct poptOption optionsTable[] = {
&transFlags, RPMTRANS_FLAG_ANACONDA|RPMTRANS_FLAG_DEPLOOPS,
N_("use anaconda \"presentation order\""), NULL},
+ { "transaction", 'T', POPT_BIT_SET, &giflags, (RPMGI_TSADD|RPMGI_TSORDER),
+ N_("do not create transaction set"), NULL},
+ { "noorder", '\0', POPT_BIT_CLR, &giflags, RPMGI_TSORDER,
+ N_("do not order transaction set"), NULL},
+ { "noglob", '\0', POPT_BIT_SET, &giflags, RPMGI_NOGLOB,
+ N_("do not glob arguments"), NULL},
+ { "nomanifest", '\0', POPT_BIT_SET, &giflags, RPMGI_NOMANIFEST,
+ N_("do not process arg manifests"), NULL},
+ { "noheader", '\0', POPT_BIT_SET, &giflags, RPMGI_NOHEADER,
+ N_("do not read headers"), NULL},
+
{ "qf", '\0', POPT_ARG_STRING, &queryFormat, 0,
N_("use the following query format"), "QUERYFORMAT" },
{ "queryformat", '\0', POPT_ARG_STRING, &queryFormat, 0,
@@ -143,18 +156,19 @@ main(int argc, char *const argv[])
int xx;
#endif
- fprintf(stderr, "%5d %s\n", ac, arg);
+ if (!(giflags & RPMGI_TSADD))
+ fprintf(stdout, "%5d %s\n", ac, arg);
arg = _free(arg);
}
ac++;
}
- if (giflags & 0x3) {
+ if (giflags & RPMGI_TSADD) {
rpmtsi tsi;
rpmte q;
int i;
-fprintf(stderr, "======================= ordered %d elements\n\
+fprintf(stdout, "======================= %d transaction elements\n\
# Tree Depth Degree Package\n\
=======================\n", rpmtsNElements(ts));
@@ -164,10 +178,10 @@ fprintf(stderr, "======================= ordered %d elements\n\
char deptypechar;
if (i == rpmtsUnorderedSuccessors(ts, -1))
- fprintf(stderr, "======================= leaf nodes only:\n");
+ fprintf(stdout, "======================= leaf nodes only:\n");
deptypechar = (rpmteType(q) == TR_REMOVED ? '-' : '+');
- fprintf(stderr, "%5d%5d%6d%7d %*s%c%s\n",
+ fprintf(stdout, "%5d%5d%6d%7d %*s%c%s\n",
i, rpmteTree(q), rpmteDepth(q), rpmteDegree(q),
(2 * rpmteDepth(q)), "",
deptypechar, rpmteNEVRA(q));
diff --git a/lib/verify.c b/lib/verify.c
index 746076d5e..35ad0b7d1 100644
--- a/lib/verify.c
+++ b/lib/verify.c
@@ -537,19 +537,7 @@ int rpmcliVerify(rpmts ts, QVA_t qva, const char ** argv)
}
ovsflags = rpmtsSetVSFlags(ts, vsflags);
- if (qva->qva_source == RPMQV_ALL) {
- /*@-nullpass@*/ /* FIX: argv can be NULL, cast to pass argv array */
- ec = rpmQueryVerify(qva, ts, (const char *) argv);
- /*@=nullpass@*/
- } else {
-/*@-boundsread@*/
- if (argv != NULL)
- while ((arg = *argv++) != NULL) {
- ec += rpmQueryVerify(qva, ts, arg);
- rpmtsEmpty(ts);
- }
-/*@=boundsread@*/
- }
+ ec = rpmcliArgIter(ts, qva, argv);
vsflags = rpmtsSetVSFlags(ts, ovsflags);
if (qva->qva_showPackage == showVerifyPackage)