From 59b275ddc7346fd8f2f9a0267949c457f4297eee Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 4 Oct 2010 14:02:53 +0300 Subject: Further streamline rpmcliArgIter() and friends - Turn applyFilters() into match iterator initializer which optionally applies filters if present - Handle NULL iterator error codes centrally in rpmcliShowMatches() --- lib/query.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/query.c b/lib/query.c index 5b847d01a..5ada52c88 100644 --- a/lib/query.c +++ b/lib/query.c @@ -287,6 +287,9 @@ static int rpmcliShowMatches(QVA_t qva, rpmts ts, rpmdbMatchIterator mi) Header h; int ec = 0; + if (mi == NULL) + return 1; + while ((h = rpmdbNextIterator(mi)) != NULL) { int rc; rpmdbCheckSignals(); @@ -493,12 +496,12 @@ exit: } /* - * Apply extra query filters. By default patterns applied to package - * name, others can be specified with = + * Initialize db iterator with optional filters. By default patterns + * applied to package name, others can be specified with = */ -static rpmRC applyFilters(rpmdbMatchIterator mi, ARGV_const_t argv) +static rpmdbMatchIterator initFilterIterator(rpmts ts, ARGV_const_t argv) { - rpmRC rc = RPMRC_OK; + rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0); for (ARGV_const_t arg = argv; arg && *arg != NULL; arg++) { rpmTag tag = RPMTAG_NAME; @@ -513,7 +516,7 @@ static rpmRC applyFilters(rpmdbMatchIterator mi, ARGV_const_t argv) tag = rpmTagGetValue(a); if (tag == RPMTAG_NOT_FOUND) { rpmlog(RPMLOG_ERR, _("unknown tag: \"%s\"\n"), a); - rc = RPMRC_FAIL; + mi = rpmdbFreeIterator(mi); break; } pat = ae; @@ -522,7 +525,7 @@ static rpmRC applyFilters(rpmdbMatchIterator mi, ARGV_const_t argv) rpmdbSetIteratorRE(mi, tag, RPMMIRE_DEFAULT, pat); } - return rc; + return mi; } int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv) @@ -531,12 +534,8 @@ int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv) switch (qva->qva_source) { case RPMQV_ALL: { - rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0); - if (applyFilters(mi, argv) != RPMRC_OK) { - ec = 1; - } else { - ec = rpmcliShowMatches(qva, ts, mi); - } + rpmdbMatchIterator mi = initFilterIterator(ts, argv); + ec = rpmcliShowMatches(qva, ts, mi); mi = rpmdbFreeIterator(mi); break; } @@ -555,7 +554,7 @@ int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_const_t argv) default: for (ARGV_const_t arg = argv; arg && *arg; arg++) { rpmdbMatchIterator mi = initQueryIterator(qva, ts, *arg); - ec += (mi != NULL) ? rpmcliShowMatches(qva, ts, mi) : 1; + ec += rpmcliShowMatches(qva, ts, mi); rpmdbFreeIterator(mi); } break; -- cgit v1.2.3