xbps-query: -s, --search is able to find pkgs by matching virtual pkgnames.

This commit is contained in:
Juan RP 2013-02-15 08:30:11 +01:00
parent 3bb41a2662
commit be1086f8fb
2 changed files with 50 additions and 6 deletions

8
NEWS
View File

@ -1,5 +1,13 @@
xbps-0.21 (???): xbps-0.21 (???):
* xbps-query(8): the search mode (-s, --search) now is able to find
packages by matching virtual package strings, i.e:
$ xbps-query -s cron-daemon
[-] cronie-1.4.9_1 [virtual] Runs specified programs at scheduled times
[-] dcron-4.5_18 [virtual] Dillon's lightweight cron daemon
$
* xbps-query(8): changed short option -M (--list-orphans) to -O; which * xbps-query(8): changed short option -M (--list-orphans) to -O; which
seems more appropiate to use. seems more appropiate to use.

View File

@ -110,20 +110,56 @@ search_pkgs_cb(struct xbps_rindex *rpi, void *arg, bool *done)
allkeys = prop_dictionary_all_keys(rpi->repod); allkeys = prop_dictionary_all_keys(rpi->repod);
for (i = 0; i < prop_array_count(allkeys); i++) { for (i = 0; i < prop_array_count(allkeys); i++) {
prop_array_t provides = NULL;
ksym = prop_array_get(allkeys, i); ksym = prop_array_get(allkeys, i);
pkgd = prop_dictionary_get_keysym(rpi->repod, ksym); pkgd = prop_dictionary_get_keysym(rpi->repod, ksym);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkgd, "short_desc", &desc); prop_dictionary_get_cstring_nocopy(pkgd, "short_desc", &desc);
provides = prop_dictionary_get(pkgd, "provides");
for (x = 0; x < sd->npatterns; x++) { for (x = 0; x < sd->npatterns; x++) {
if ((xbps_pkgpattern_match(pkgver, sd->patterns[x]) == 0) && size_t j;
(strcasestr(pkgver, sd->patterns[x]) == 0) && bool vpkgfound = false;
(strcasestr(desc, sd->patterns[x]) == 0))
continue;
prop_array_add_cstring_nocopy(sd->results, pkgver); for (j = 0; j < prop_array_count(provides); j++) {
prop_array_add_cstring_nocopy(sd->results, desc); const char *vpkgver;
char *tmp, *vpkgname;
prop_array_get_cstring_nocopy(provides, j, &vpkgver);
if (strchr(vpkgver, '_') == NULL)
tmp = xbps_xasprintf("%s_1", vpkgver);
else
tmp = strdup(vpkgver);
vpkgname = xbps_pkg_name(tmp);
if (strcasecmp(vpkgname, sd->patterns[x]) == 0) {
free(vpkgname);
free(tmp);
vpkgfound = true;
break;
}
free(vpkgname);
free(tmp);
}
if (vpkgfound) {
prop_string_t pstr;
pstr = prop_string_create();
prop_string_append_cstring(pstr, pkgver);
prop_string_append_cstring(pstr, " [virtual]");
prop_array_add(sd->results, pstr);
prop_object_release(pstr);
prop_array_add_cstring_nocopy(sd->results, desc);
}
if ((xbps_pkgpattern_match(pkgver, sd->patterns[x])) ||
(strcasestr(pkgver, sd->patterns[x])) ||
(strcasestr(desc, sd->patterns[x]))) {
prop_array_add_cstring_nocopy(sd->results, pkgver);
prop_array_add_cstring_nocopy(sd->results, desc);
continue;
}
} }
} }
prop_object_release(allkeys); prop_object_release(allkeys);