[pacman-dev] [PATCH] Handle provides with -Q
Andrew Gregory
andrew.gregory.8 at gmail.com
Fri Apr 1 12:26:03 UTC 2016
On 04/01/16 at 02:23pm, Allan McRae wrote:
> 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".
s/Querying the what package/Querying the package that provides/?
> 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;
> +}
The package can be returned immediately, so there's no need for the
found/break. More importantly, because pkg is used to refer to the
package currently being checked, if no provider is found it will just
return the last package in the list:
pacman -Qi not-a-real-package-name # prints zziplib
> +
> 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);
Any reason not to just use alpm_find_satisfier here?
> + }
> }
>
> if(pkg == NULL) {
> --
> 2.7.4
More information about the pacman-dev
mailing list