[Rpm-maint] [PATCH] allowing -q to work both for binary files and installed packages

Rakesh Pandit rakesh.pandit at gmail.com
Wed May 27 19:15:35 UTC 2009


$subject

I have kept all behavior same except that after usual db check if no
match found check for .rpm extension and file presence with read
access and then read from bin file. Rest flags back and continue the
normal behaviour.

Review?

Link: http://rakesh.fedorapeople.org/rpm/0006-Handle-q-query-with-extention-.rpm-and-query-them-a.patch

All patches in serial: http://rakesh.fedorapeople.org/rpm/

--
Regards,
rakesh

>From e207b51b709fd9563c5e8425b2b7924308e616fa Mon Sep 17 00:00:00 2001
From: Rakesh Pandit <rakesh at fedoraproject.org>
Date: Thu, 28 May 2009 00:23:14 +0530
Subject: [PATCH] Handle -q query with extention .rpm and query them as
binary files
 - remove static from rpmgiLoadReadHeader and introduce new rpmgiSetFlags

---
 lib/query.c |   22 ++++++++++++++++++++++
 lib/rpmgi.h |   16 ++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/lib/query.c b/lib/query.c
index e510ef8..9a1787d 100644
--- a/lib/query.c
+++ b/lib/query.c
@@ -537,13 +537,35 @@ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg)
     case RPMQV_PACKAGE:
     {
 	int matches = 0;
+	rpmRC rpmrc = RPMRC_NOTFOUND;
 	rpmdbMatchIterator mi;
+	rpmgi gi;
+	Header h;
+
 	mi = rpmtsInitIterator(ts, RPMDBI_LABEL, arg, 0);
 	while (rpmdbNextIterator(mi) != NULL) {
 	    matches++;
 	}
 	rpmdbFreeIterator(mi);
 	if (! matches) {
+	    if (strcmp(arg, ".rpm") && (access(arg, R_OK) == 0)) {
+	        gi = qva->qva_gi;
+		rpmgiSetFlags(gi, giFlags);
+
+		rpmrc = rpmgiLoadReadHeader(gi);
+		if (rpmrc == RPMRC_OK) {
+	            h = rpmgiHeader(gi);
+		    if (h != NULL) {
+		        qva->qva_showPackage(qva, ts, h);
+			rpmgiSetFlags(gi, (RPMGI_NOGLOB|RPMGI_NOHEADER));
+			break;
+		    }
+		}
+
+		/* Set flags back */
+		rpmgiSetFlags(gi, (RPMGI_NOGLOB|RPMGI_NOHEADER));
+
+	    }
 	    rpmlog(RPMLOG_NOTICE, _("package %s is not installed\n"), arg);
 	    res = 1;
 	} else {
diff --git a/lib/rpmgi.h b/lib/rpmgi.h
index 408e907..c0a33b8 100644
--- a/lib/rpmgi.h
+++ b/lib/rpmgi.h
@@ -112,6 +112,13 @@ rpmts rpmgiTs(rpmgi gi);
 rpmRC rpmgiSetArgs(rpmgi gi, ARGV_const_t argv,
 		int ftsOpts, rpmgiFlags flags);

+/** \ingroup rpmgi
+ * Load flags.
+ * @param gi		generalized iterator
+ * @param flags		iterator flags
+ * @return 		RPMRC_OK on success
+ */
+rpmRC rpmgiSetFlags(rpmgi gi, rpmgiFlags flags);

 /** \ingroup rpmgi
  * Retrieve iterator flags
@@ -127,6 +134,15 @@ rpmgiFlags rpmgiGetFlags(rpmgi gi);
  */
 int rpmgiNumErrors(rpmgi gi);

+/** \ingroup rpmgi
+ * Read next header from package, lazily expanding manifests as found.
+ * @todo An empty file read as manifest truncates argv returning
RPMRC_NOTFOUND.
+ * @todo Chained manifests lose an arg someplace.
+ * @param gi		generalized iterator
+ * @return		RPMRC_OK on success
+ */
+rpmRC rpmgiLoadReadHeader(rpmgi gi);
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.6.0.6


More information about the Rpm-maint mailing list