xbps-repo(8): the 'find-files' target now accepts multiple patterns.

This commit is contained in:
Juan RP 2011-12-22 11:01:28 +01:00
parent d4278be914
commit 47237846ae
5 changed files with 40 additions and 14 deletions

3
NEWS
View File

@ -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*' ...

View File

@ -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 *);

View File

@ -32,14 +32,22 @@
#include <xbps_api.h>
#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,11 +66,14 @@ 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))
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;
}

View File

@ -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");

View File

@ -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