summaryrefslogtreecommitdiff
path: root/lib/query.c
diff options
context:
space:
mode:
authorRakesh Pandit <rakesh@fedoraproject.org>2009-03-14 17:59:03 +0530
committerPanu Matilainen <pmatilai@redhat.com>2009-04-23 12:14:58 +0300
commit5bb4b0928393a4534d9f76644f7b3d3c74ceb3f2 (patch)
tree4cbf7f26d7061ffc85db0f50e16b3bb223526491 /lib/query.c
parente77498808e58a8041d3a16450fab400116aca28d (diff)
downloadlibrpm-tizen-5bb4b0928393a4534d9f76644f7b3d3c74ceb3f2.tar.gz
librpm-tizen-5bb4b0928393a4534d9f76644f7b3d3c74ceb3f2.tar.bz2
librpm-tizen-5bb4b0928393a4534d9f76644f7b3d3c74ceb3f2.zip
Cleanup: Move similar patterns in rpmcliArgIter to rpmcliArgIterHelper.
Diffstat (limited to 'lib/query.c')
-rw-r--r--lib/query.c78
1 files changed, 27 insertions, 51 deletions
diff --git a/lib/query.c b/lib/query.c
index 061758456..a11d29c3e 100644
--- a/lib/query.c
+++ b/lib/query.c
@@ -558,69 +558,46 @@ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg)
return res;
}
-int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv)
+static int rpmcliArgIterHelper(rpmts ts, QVA_t qva, rpmTag tag, ARGV_const_t argv, rpmgiFlags gFlgs)
{
rpmRC rpmrc = RPMRC_NOTFOUND;
int ec = 0;
+ qva->qva_gi = rpmgiNew(ts, tag, NULL, 0);
+ qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, gFlgs);
+
+ if (qva->qva_gi != NULL && (rpmgiGetFlags(qva->qva_gi) & RPMGI_TSADD)) /* Load the ts with headers. */
+ while ((rpmrc = rpmgiNext(qva->qva_gi)) == RPMRC_OK)
+ {};
+ if (rpmrc != RPMRC_NOTFOUND) {
+ qva->qva_gi = rpmgiFree(qva->qva_gi);
+ return 1; /* XXX should be no. of failures. */
+ }
+ /* FIX: argv can be NULL, cast to pass argv array */
+ ec = rpmQueryVerify(qva, ts, (tag == RPMDBI_PACKAGES)? (const char *) argv : NULL);
+ rpmtsEmpty(ts);
+ qva->qva_gi = rpmgiFree(qva->qva_gi);
+ return ec;
+}
+
+int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv)
+{
+ int ec = 0;
+
switch (qva->qva_source) {
case RPMQV_ALL:
- qva->qva_gi = rpmgiNew(ts, RPMDBI_PACKAGES, NULL, 0);
- qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, RPMGI_NONE);
-
- if (qva->qva_gi != NULL && (rpmgiGetFlags(qva->qva_gi) & RPMGI_TSADD)) /* Load the ts with headers. */
- while ((rpmrc = rpmgiNext(qva->qva_gi)) == RPMRC_OK)
- {};
- if (rpmrc != RPMRC_NOTFOUND)
- return 1; /* XXX should be no. of failures. */
-
- /* FIX: argv can be NULL, cast to pass argv array */
- ec = rpmQueryVerify(qva, ts, (const char *) argv);
- rpmtsEmpty(ts);
+ ec = rpmcliArgIterHelper(ts, qva, RPMDBI_PACKAGES, argv, RPMGI_NONE);
break;
case RPMQV_RPM:
- qva->qva_gi = rpmgiNew(ts, RPMDBI_ARGLIST, NULL, 0);
- qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, giFlags);
-
- if (qva->qva_gi != NULL && (rpmgiGetFlags(qva->qva_gi) & RPMGI_TSADD)) /* Load the ts with headers. */
- while ((rpmrc = rpmgiNext(qva->qva_gi)) == RPMRC_OK)
- {};
- if (rpmrc != RPMRC_NOTFOUND)
- return 1; /* XXX should be no. of failures. */
-
- /* FIX: argv can be NULL, cast to pass argv array */
- ec = rpmQueryVerify(qva, ts, NULL);
- rpmtsEmpty(ts);
+ ec = rpmcliArgIterHelper(ts, qva, RPMDBI_ARGLIST, argv, giFlags);
break;
case RPMQV_HDLIST:
- qva->qva_gi = rpmgiNew(ts, RPMDBI_HDLIST, NULL, 0);
- qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, giFlags);
-
- if (qva->qva_gi != NULL && (rpmgiGetFlags(qva->qva_gi) & RPMGI_TSADD)) /* Load the ts with headers. */
- while ((rpmrc = rpmgiNext(qva->qva_gi)) == RPMRC_OK)
- {};
- if (rpmrc != RPMRC_NOTFOUND)
- return 1; /* XXX should be no. of failures. */
-
- /* FIX: argv can be NULL, cast to pass argv array */
- ec = rpmQueryVerify(qva, ts, NULL);
- rpmtsEmpty(ts);
+ ec = rpmcliArgIterHelper(ts, qva, RPMDBI_HDLIST, argv, giFlags);
break;
case RPMQV_FTSWALK:
if (ftsOpts == 0)
ftsOpts = (RPMGI_COMFOLLOW | RPMGI_LOGICAL | RPMGI_NOSTAT);
- qva->qva_gi = rpmgiNew(ts, RPMDBI_FTSWALK, NULL, 0);
- qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, giFlags);
-
- if (qva->qva_gi != NULL && (rpmgiGetFlags(qva->qva_gi) & RPMGI_TSADD)) /* Load the ts with headers. */
- while ((rpmrc = rpmgiNext(qva->qva_gi)) == RPMRC_OK)
- {};
- if (rpmrc != RPMRC_NOTFOUND)
- return 1; /* XXX should be no. of failures. */
-
- /* FIX: argv can be NULL, cast to pass argv array */
- ec = rpmQueryVerify(qva, ts, NULL);
- rpmtsEmpty(ts);
+ ec = rpmcliArgIterHelper(ts, qva, RPMDBI_FTSWALK, argv, giFlags);
break;
default:
qva->qva_gi = rpmgiNew(ts, RPMDBI_ARGLIST, NULL, 0);
@@ -630,11 +607,10 @@ int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv)
ec += rpmQueryVerify(qva, ts, rpmgiHdrPath(qva->qva_gi));
rpmtsEmpty(ts);
}
+ qva->qva_gi = rpmgiFree(qva->qva_gi);
break;
}
- qva->qva_gi = rpmgiFree(qva->qva_gi);
-
return ec;
}