dcavalca / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
James Antill ee2eaf
From 013cd4ba63c35fa75feeccde0022d56e68bc5845 Mon Sep 17 00:00:00 2001
James Antill ee2eaf
From: Michal Domonkos <mdomonko@redhat.com>
James Antill ee2eaf
Date: Mon, 16 Aug 2021 18:21:02 +0200
James Antill ee2eaf
Subject: [PATCH] Add support for RPMDBI_BASENAMES on file queries
James Antill ee2eaf
James Antill ee2eaf
There are legitimate reasons (such as rhbz#1940895 or the included test)
James Antill ee2eaf
for wanting the former behavior where all file states were considered in
James Antill ee2eaf
file queries prior to commit 9ad57bda4a82b9847826daa766b4421d877bb3d9,
James Antill ee2eaf
so celebrate the tenth anniversary of that commit by adding a CLI switch
James Antill ee2eaf
(a new package selector --path), as contemplated back then.
James Antill ee2eaf
James Antill ee2eaf
Update the man page for --file to reflect it's current behavior and make
James Antill ee2eaf
--path that more obvious.
James Antill ee2eaf
James Antill ee2eaf
Resolves: rhbz#1940895
James Antill ee2eaf
James Antill ee2eaf
Combined with:
James Antill ee2eaf
d1aebda01033bc8ba0d748b49f6fad9a5c0caa3f
James Antill ee2eaf
f62b6d27cd741406a52a7e9c5b1d6f581dbd3af8
James Antill ee2eaf
James Antill ee2eaf
Backported for 4.14.3.
James Antill ee2eaf
---
James Antill ee2eaf
 doc/rpm.8         |  9 ++++++--
James Antill ee2eaf
 lib/poptQV.c      |  6 +++++-
James Antill ee2eaf
 lib/query.c       |  7 +++++--
James Antill ee2eaf
 lib/rpmcli.h      |  1 +
James Antill ee2eaf
 tests/rpmquery.at | 52 +++++++++++++++++++++++++++++++++++++++++++++++
James Antill ee2eaf
 5 files changed, 70 insertions(+), 5 deletions(-)
James Antill ee2eaf
James Antill ee2eaf
diff --git a/doc/rpm.8 b/doc/rpm.8
James Antill ee2eaf
index 15a3db25f..74604c8ec 100644
James Antill ee2eaf
--- a/doc/rpm.8
James Antill ee2eaf
+++ b/doc/rpm.8
James Antill ee2eaf
@@ -57,7 +57,7 @@ rpm \- RPM Package Manager
James Antill ee2eaf
 .PP
James Antill ee2eaf
 
James Antill ee2eaf
  [\fB\fIPACKAGE_NAME\fB\fR]
James Antill ee2eaf
- [\fB-a,--all [\fISELECTOR\fR]\fR] [\fB-f,--file \fIFILE\fB\fR]
James Antill ee2eaf
+ [\fB-a,--all [\fISELECTOR\fR]\fR] [\fB-f,--file \fIFILE\fB\fR] [\fB--path \fIPATH\fB\fR]
James Antill ee2eaf
  [\fB-g,--group \fIGROUP\fB\fR] {\fB-p,--package \fIPACKAGE_FILE\fB\fR]
James Antill ee2eaf
  [\fB--hdrid \fISHA1\fB\fR] [\fB--pkgid \fIMD5\fB\fR] [\fB--tid \fITID\fB\fR]
James Antill ee2eaf
  [\fB--querybynumber \fIHDRNUM\fB\fR] [\fB--triggeredby \fIPACKAGE_NAME\fB\fR]
James Antill ee2eaf
@@ -555,7 +555,7 @@ starts with "b".
James Antill ee2eaf
 List duplicated packages.
James Antill ee2eaf
 .TP
James Antill ee2eaf
 \fB-f, --file \fIFILE\fB\fR
James Antill ee2eaf
-Query package owning \fIFILE\fR.
James Antill ee2eaf
+Query package owning installed \fIFILE\fR.
James Antill ee2eaf
 .TP
James Antill ee2eaf
 \fB--filecaps\fR
James Antill ee2eaf
 List file names with POSIX1.e capabilities.
James Antill ee2eaf
@@ -598,6 +598,11 @@ that will be expanded to paths that are substituted in place of
James Antill ee2eaf
 the package manifest as additional \fIPACKAGE_FILE\fR
James Antill ee2eaf
 arguments to the query.
James Antill ee2eaf
 .TP
James Antill ee2eaf
+\fB--path \fIPATH\fB\fR
James Antill ee2eaf
+Query package(s) owning \fIPATH\fR, whether the file is installed or not.
James Antill ee2eaf
+Multiple packages may own a \fIPATH\fR, but the file is only owned by the
James Antill ee2eaf
+package installed last.
James Antill ee2eaf
+.TP
James Antill ee2eaf
 \fB--pkgid \fIMD5\fB\fR
James Antill ee2eaf
 Query package that contains a given package identifier, i.e. the
James Antill ee2eaf
 \fIMD5\fR digest of the combined header and
James Antill ee2eaf
diff --git a/lib/poptQV.c b/lib/poptQV.c
James Antill ee2eaf
index 9021d7b3c..f752d8b82 100644
James Antill ee2eaf
--- a/lib/poptQV.c
James Antill ee2eaf
+++ b/lib/poptQV.c
James Antill ee2eaf
@@ -27,6 +27,7 @@ struct rpmQVKArguments_s rpmQVKArgs;
James Antill ee2eaf
 #define POPT_WHATENHANCES	-1014
James Antill ee2eaf
 #define POPT_WHATOBSOLETES	-1015
James Antill ee2eaf
 #define POPT_WHATCONFLICTS	-1016
James Antill ee2eaf
+#define POPT_QUERYBYPATH	-1017
James Antill ee2eaf
 
James Antill ee2eaf
 /* ========== Query/Verify/Signature source args */
James Antill ee2eaf
 static void rpmQVSourceArgCallback( poptContext con,
James Antill ee2eaf
@@ -58,6 +59,7 @@ static void rpmQVSourceArgCallback( poptContext con,
James Antill ee2eaf
     case POPT_WHATSUPPLEMENTS: qva->qva_source |= RPMQV_WHATSUPPLEMENTS; break;
James Antill ee2eaf
     case POPT_WHATENHANCES: qva->qva_source |= RPMQV_WHATENHANCES; break;
James Antill ee2eaf
     case POPT_TRIGGEREDBY: qva->qva_source |= RPMQV_TRIGGEREDBY; break;
James Antill ee2eaf
+    case POPT_QUERYBYPATH: qva->qva_source |= RPMQV_PATH_ALL; break;
James Antill ee2eaf
     case POPT_QUERYBYPKGID: qva->qva_source |= RPMQV_PKGID; break;
James Antill ee2eaf
     case POPT_QUERYBYHDRID: qva->qva_source |= RPMQV_HDRID; break;
James Antill ee2eaf
     case POPT_QUERYBYTID: qva->qva_source |= RPMQV_TID; break;
James Antill ee2eaf
@@ -80,7 +82,9 @@ struct poptOption rpmQVSourcePoptTable[] = {
James Antill ee2eaf
  { "checksig", 'K', POPT_ARGFLAG_DOC_HIDDEN, NULL, 'K',
James Antill ee2eaf
 	N_("rpm checksig mode"), NULL },
James Antill ee2eaf
  { "file", 'f', 0, 0, 'f',
James Antill ee2eaf
-	N_("query/verify package(s) owning file"), "FILE" },
James Antill ee2eaf
+	N_("query/verify package(s) owning installed file"), "FILE" },
James Antill ee2eaf
+ { "path", '\0', 0, 0, POPT_QUERYBYPATH,
James Antill ee2eaf
+	N_("query/verify package(s) owning path, installed or not"), "PATH" },
James Antill ee2eaf
  { "group", 'g', 0, 0, 'g',
James Antill ee2eaf
 	N_("query/verify package(s) in group"), "GROUP" },
James Antill ee2eaf
  { "package", 'p', 0, 0, 'p',
James Antill ee2eaf
diff --git a/lib/query.c b/lib/query.c
James Antill ee2eaf
index 26cdecf10..e6ea1fa2d 100644
James Antill ee2eaf
--- a/lib/query.c
James Antill ee2eaf
+++ b/lib/query.c
James Antill ee2eaf
@@ -440,6 +440,7 @@ static rpmdbMatchIterator initQueryIterator(QVA_t qva, rpmts ts, const char * ar
James Antill ee2eaf
 	}
James Antill ee2eaf
 	/* fallthrough on absolute and relative paths */
James Antill ee2eaf
     case RPMQV_PATH:
James Antill ee2eaf
+    case RPMQV_PATH_ALL:
James Antill ee2eaf
     {   char * fn;
James Antill ee2eaf
 
James Antill ee2eaf
 	for (s = arg; *s != '\0'; s++)
James Antill ee2eaf
@@ -458,8 +459,10 @@ static rpmdbMatchIterator initQueryIterator(QVA_t qva, rpmts ts, const char * ar
James Antill ee2eaf
 	    fn = xstrdup(arg);
James Antill ee2eaf
 	(void) rpmCleanPath(fn);
James Antill ee2eaf
 
James Antill ee2eaf
-	/* XXX Add a switch to enable former BASENAMES behavior? */
James Antill ee2eaf
-	mi = rpmtsInitIterator(ts, RPMDBI_INSTFILENAMES, fn, 0);
James Antill ee2eaf
+	rpmDbiTagVal tag = RPMDBI_INSTFILENAMES;
James Antill ee2eaf
+	if (qva->qva_source == RPMQV_PATH_ALL)
James Antill ee2eaf
+	    tag = RPMDBI_BASENAMES;
James Antill ee2eaf
+	mi = rpmtsInitIterator(ts, tag, fn, 0);
James Antill ee2eaf
 	if (mi == NULL)
James Antill ee2eaf
 	    mi = rpmtsInitIterator(ts, RPMDBI_PROVIDENAME, fn, 0);
James Antill ee2eaf
 
James Antill ee2eaf
diff --git a/lib/rpmcli.h b/lib/rpmcli.h
James Antill ee2eaf
index 99af2585a..c0d07d137 100644
James Antill ee2eaf
--- a/lib/rpmcli.h
James Antill ee2eaf
+++ b/lib/rpmcli.h
James Antill ee2eaf
@@ -102,6 +102,7 @@ enum rpmQVSources_e {
James Antill ee2eaf
     RPMQV_SPECBUILTRPMS,	/*!< ... from pkgs which would be built from spec */
James Antill ee2eaf
     RPMQV_WHATOBSOLETES,	/*!< ... from obsoletes db search. */
James Antill ee2eaf
     RPMQV_WHATCONFLICTS,	/*!< ... from conflicts db search. */
James Antill ee2eaf
+    RPMQV_PATH_ALL,	/*!< ... from file path db search (all states). */
James Antill ee2eaf
 };
James Antill ee2eaf
 
James Antill ee2eaf
 typedef rpmFlags rpmQVSources;
James Antill ee2eaf
diff --git a/tests/rpmquery.at b/tests/rpmquery.at
James Antill ee2eaf
index 36c62339a..ad580f664 100644
James Antill ee2eaf
--- a/tests/rpmquery.at
James Antill ee2eaf
+++ b/tests/rpmquery.at
James Antill ee2eaf
@@ -194,6 +194,58 @@ runroot rpm \
James Antill ee2eaf
 
James Antill ee2eaf
 AT_CLEANUP
James Antill ee2eaf
 
James Antill ee2eaf
+# ------------------------------
James Antill ee2eaf
+# query a package by a file
James Antill ee2eaf
+AT_SETUP([rpm -qf])
James Antill ee2eaf
+AT_KEYWORDS([query])
James Antill ee2eaf
+AT_CHECK([
James Antill ee2eaf
+RPMDB_INIT
James Antill ee2eaf
+runroot rpm \
James Antill ee2eaf
+  --nodeps \
James Antill ee2eaf
+  -i /data/RPMS/hello-1.0-1.i386.rpm
James Antill ee2eaf
+runroot rpm \
James Antill ee2eaf
+  -qf /usr/local/bin/hello
James Antill ee2eaf
+],
James Antill ee2eaf
+[0],
James Antill ee2eaf
+[hello-1.0-1.i386
James Antill ee2eaf
+],
James Antill ee2eaf
+[])
James Antill ee2eaf
+AT_CLEANUP
James Antill ee2eaf
+
James Antill ee2eaf
+AT_SETUP([rpm -qf on non-installed file])
James Antill ee2eaf
+AT_KEYWORDS([query])
James Antill ee2eaf
+AT_CHECK([
James Antill ee2eaf
+RPMDB_INIT
James Antill ee2eaf
+runroot rpm \
James Antill ee2eaf
+  --nodeps \
James Antill ee2eaf
+  --excludedocs \
James Antill ee2eaf
+  -i /data/RPMS/hello-1.0-1.i386.rpm
James Antill ee2eaf
+runroot rpm \
James Antill ee2eaf
+  -qf /usr/share/doc/hello-1.0/FAQ
James Antill ee2eaf
+],
James Antill ee2eaf
+[1],
James Antill ee2eaf
+[],
James Antill ee2eaf
+[error: file /usr/share/doc/hello-1.0/FAQ: No such file or directory
James Antill ee2eaf
+])
James Antill ee2eaf
+AT_CLEANUP
James Antill ee2eaf
+
James Antill ee2eaf
+AT_SETUP([rpm -q --path on non-installed file])
James Antill ee2eaf
+AT_KEYWORDS([query])
James Antill ee2eaf
+AT_CHECK([
James Antill ee2eaf
+RPMDB_INIT
James Antill ee2eaf
+runroot rpm \
James Antill ee2eaf
+  --nodeps \
James Antill ee2eaf
+  --excludedocs \
James Antill ee2eaf
+  -i /data/RPMS/hello-1.0-1.i386.rpm
James Antill ee2eaf
+runroot rpm \
James Antill ee2eaf
+  -q --path /usr/share/doc/hello-1.0/FAQ
James Antill ee2eaf
+],
James Antill ee2eaf
+[0],
James Antill ee2eaf
+[hello-1.0-1.i386
James Antill ee2eaf
+],
James Antill ee2eaf
+[])
James Antill ee2eaf
+AT_CLEANUP
James Antill ee2eaf
+
James Antill ee2eaf
 # ------------------------------
James Antill ee2eaf
 AT_SETUP([integer array query])
James Antill ee2eaf
 AT_KEYWORDS([query])
James Antill ee2eaf
-- 
James Antill ee2eaf
2.35.1
James Antill ee2eaf