[pacman-dev] [PATCH] Handle provides with -Q

Allan McRae allan at archlinux.org
Fri Apr 1 04:23:32 UTC 2016


It is useful to be able to use "pacman -Qi" on any dependency, even if that
dependency is a provide.  For example, on Arch Linux systems, "sh" is provided
by the "bash" package, and many packages depend on "sh". Querying the what
package the "sh" dependency, currently first requires searching for "sh".

This patch allows the use of "pacman -Qi" on a provide.

Fixes FS#20650.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 src/pacman/query.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/pacman/query.c b/src/pacman/query.c
index 0cc12e6..19e4b3f 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -80,6 +80,32 @@ static int search_path(char **filename, struct stat *bufptr)
 	return -1;
 }
 
+static alpm_pkg_t *find_provider(alpm_db_t *db_local, const char *name)
+{
+	alpm_list_t *packages, *i;
+	alpm_pkg_t *pkg = NULL;
+	int found = 0;
+
+	packages = alpm_db_get_pkgcache(db_local);
+
+	for(i = packages; i && !found; i = alpm_list_next(i)) {
+		alpm_list_t *provides, *p;
+
+		pkg = i->data;
+		provides = alpm_pkg_get_provides(pkg);
+
+		for(p = provides; p; p = alpm_list_next(p)) {
+			alpm_depend_t *d = p->data;
+			if(strcmp(name, d->name) == 0) {
+				found = 1;
+				break;
+			}
+		}
+	}
+
+	return pkg;
+}
+
 static void print_query_fileowner(const char *filename, alpm_pkg_t *info)
 {
 	if(!config->quiet) {
@@ -462,6 +488,10 @@ int pacman_query(alpm_list_t *targets)
 			alpm_pkg_load(config->handle, strname, 1, 0, &pkg);
 		} else {
 			pkg = alpm_db_get_pkg(db_local, strname);
+			/* if pkg is not found, return the first package that provides it */
+			if(pkg == NULL) {
+				pkg = find_provider(db_local, strname);
+			}
 		}
 
 		if(pkg == NULL) {
-- 
2.7.4


More information about the pacman-dev mailing list