diff --git a/NEWS b/NEWS index c0970116..6281f767 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ xbps-0.11.1 (???): + * xbps-repo(8): the 'find-files' target accepts multiple patterns, such as: + $ xbps-repo find-files /bin/cat '/bin/f*' ... + * xbps-bin(8): the 'find-files' target accepts multiple patterns, such as: $ xbps-bin find-files /bin/cat '/bin/f*' ... diff --git a/bin/xbps-repo/defs.h b/bin/xbps-repo/defs.h index 7ce90729..26d37f78 100644 --- a/bin/xbps-repo/defs.h +++ b/bin/xbps-repo/defs.h @@ -42,7 +42,7 @@ struct repo_search_data { int repo_genindex(const char *); /* From find-files.c */ -int repo_find_files_in_packages(const char *); +int repo_find_files_in_packages(int, char **); /* From list.c */ int repo_pkg_list_cb(struct repository_pool_index *, void *, bool *); diff --git a/bin/xbps-repo/find-files.c b/bin/xbps-repo/find-files.c index 9069949f..de46a7d6 100644 --- a/bin/xbps-repo/find-files.c +++ b/bin/xbps-repo/find-files.c @@ -32,14 +32,22 @@ #include #include "defs.h" +struct ffdata { + int npatterns; + char **patterns; +}; + static int -match_files_by_pattern(prop_dictionary_t pkg_filesd, prop_dictionary_keysym_t key, - const char *pattern, const char *pkgver) +match_files_by_pattern(prop_dictionary_t pkg_filesd, + prop_dictionary_keysym_t key, + struct ffdata *ffd, + const char *pkgver) { prop_object_iterator_t iter; prop_array_t array; prop_object_t obj; const char *keyname, *filestr, *typestr; + int i; keyname = prop_dictionary_keysym_cstring_nocopy(key); array = prop_dictionary_get_keysym(pkg_filesd, key); @@ -58,10 +66,13 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd, prop_dictionary_keysym_t ke iter = prop_array_iterator(array); while ((obj = prop_object_iterator_next(iter))) { prop_dictionary_get_cstring_nocopy(obj, "file", &filestr); - if ((strcmp(filestr, pattern) == 0) || - (strstr(filestr, pattern)) || - (xbps_pkgpattern_match(filestr, pattern) == 1)) - printf(" %s: %s (%s)\n", pkgver, filestr, typestr); + for (i = 1; i < ffd->npatterns; i++) { + if ((strcmp(filestr, ffd->patterns[i]) == 0) || + (strstr(filestr, ffd->patterns[i])) || + (xbps_pkgpattern_match(filestr, + ffd->patterns[i]) == 1)) + printf(" %s: %s (%s)\n", pkgver, filestr, typestr); + } } prop_object_iterator_release(iter); return 0; @@ -74,7 +85,8 @@ find_files_in_package(struct repository_pool_index *rpi, void *arg, bool *done) prop_array_t files_keys; prop_object_t obj; prop_object_iterator_t iter; - const char *pkgname, *pkgver, *pattern = arg; + struct ffdata *ffd = arg; + const char *pkgname, *pkgver; char *url; int rv = 0; unsigned int i, count; @@ -108,7 +120,7 @@ find_files_in_package(struct repository_pool_index *rpi, void *arg, bool *done) count = prop_array_count(files_keys); for (i = 0; i < count; i++) { rv = match_files_by_pattern(pkg_filesd, - prop_array_get(files_keys, i), pattern, pkgver); + prop_array_get(files_keys, i), ffd, pkgver); if (rv == -1) break; } @@ -122,8 +134,18 @@ find_files_in_package(struct repository_pool_index *rpi, void *arg, bool *done) } int -repo_find_files_in_packages(const char *pattern) +repo_find_files_in_packages(int npatterns, char **patterns) { - return xbps_repository_pool_foreach(find_files_in_package, - __UNCONST(pattern)); + struct ffdata *ffd; + int rv; + + ffd = malloc(sizeof(*ffd)); + if (ffd == NULL) + return ENOMEM; + + ffd->npatterns = npatterns; + ffd->patterns = patterns; + rv = xbps_repository_pool_foreach(find_files_in_package, ffd); + free(ffd); + return rv; } diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index ae29f010..d6dfe9ba 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -225,10 +225,10 @@ main(int argc, char **argv) prop_object_release(pkgd); } else if (strcasecmp(argv[0], "find-files") == 0) { /* Finds files by patterns, exact matches and components. */ - if (argc != 2) + if (argc < 2) usage(xhp); - rv = repo_find_files_in_packages(argv[1]); + rv = repo_find_files_in_packages(argc, argv); if (rv == ENOTSUP) { xbps_error_printf("xbps-repo: no repositories " "currently registered!\n"); diff --git a/bin/xbps-repo/xbps-repo.8 b/bin/xbps-repo/xbps-repo.8 index d93fbe93..85c1d8e2 100644 --- a/bin/xbps-repo/xbps-repo.8 +++ b/bin/xbps-repo/xbps-repo.8 @@ -58,6 +58,7 @@ Please note that all targets are case insensitive. Prints the name of .Em package(s) matching the pattern on its file list by looking in all repositories index files. +Multiple patterns can be specified as arguments. .It Sy genindex Pa /path/to/local/repo Generates a package index for a local repository as specified in its argument. It will look for archives with the