xbps-repo(8): the 'find-files' target now accepts multiple patterns.
This commit is contained in:
parent
d4278be914
commit
47237846ae
3
NEWS
3
NEWS
@ -1,5 +1,8 @@
|
|||||||
xbps-0.11.1 (???):
|
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(8): the 'find-files' target accepts multiple patterns, such as:
|
||||||
$ xbps-bin find-files /bin/cat '/bin/f*' ...
|
$ xbps-bin find-files /bin/cat '/bin/f*' ...
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ struct repo_search_data {
|
|||||||
int repo_genindex(const char *);
|
int repo_genindex(const char *);
|
||||||
|
|
||||||
/* From find-files.c */
|
/* From find-files.c */
|
||||||
int repo_find_files_in_packages(const char *);
|
int repo_find_files_in_packages(int, char **);
|
||||||
|
|
||||||
/* From list.c */
|
/* From list.c */
|
||||||
int repo_pkg_list_cb(struct repository_pool_index *, void *, bool *);
|
int repo_pkg_list_cb(struct repository_pool_index *, void *, bool *);
|
||||||
|
@ -32,14 +32,22 @@
|
|||||||
#include <xbps_api.h>
|
#include <xbps_api.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
|
struct ffdata {
|
||||||
|
int npatterns;
|
||||||
|
char **patterns;
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
match_files_by_pattern(prop_dictionary_t pkg_filesd, prop_dictionary_keysym_t key,
|
match_files_by_pattern(prop_dictionary_t pkg_filesd,
|
||||||
const char *pattern, const char *pkgver)
|
prop_dictionary_keysym_t key,
|
||||||
|
struct ffdata *ffd,
|
||||||
|
const char *pkgver)
|
||||||
{
|
{
|
||||||
prop_object_iterator_t iter;
|
prop_object_iterator_t iter;
|
||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
prop_object_t obj;
|
prop_object_t obj;
|
||||||
const char *keyname, *filestr, *typestr;
|
const char *keyname, *filestr, *typestr;
|
||||||
|
int i;
|
||||||
|
|
||||||
keyname = prop_dictionary_keysym_cstring_nocopy(key);
|
keyname = prop_dictionary_keysym_cstring_nocopy(key);
|
||||||
array = prop_dictionary_get_keysym(pkg_filesd, 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);
|
iter = prop_array_iterator(array);
|
||||||
while ((obj = prop_object_iterator_next(iter))) {
|
while ((obj = prop_object_iterator_next(iter))) {
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "file", &filestr);
|
prop_dictionary_get_cstring_nocopy(obj, "file", &filestr);
|
||||||
if ((strcmp(filestr, pattern) == 0) ||
|
for (i = 1; i < ffd->npatterns; i++) {
|
||||||
(strstr(filestr, pattern)) ||
|
if ((strcmp(filestr, ffd->patterns[i]) == 0) ||
|
||||||
(xbps_pkgpattern_match(filestr, pattern) == 1))
|
(strstr(filestr, ffd->patterns[i])) ||
|
||||||
printf(" %s: %s (%s)\n", pkgver, filestr, typestr);
|
(xbps_pkgpattern_match(filestr,
|
||||||
|
ffd->patterns[i]) == 1))
|
||||||
|
printf(" %s: %s (%s)\n", pkgver, filestr, typestr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
prop_object_iterator_release(iter);
|
prop_object_iterator_release(iter);
|
||||||
return 0;
|
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_array_t files_keys;
|
||||||
prop_object_t obj;
|
prop_object_t obj;
|
||||||
prop_object_iterator_t iter;
|
prop_object_iterator_t iter;
|
||||||
const char *pkgname, *pkgver, *pattern = arg;
|
struct ffdata *ffd = arg;
|
||||||
|
const char *pkgname, *pkgver;
|
||||||
char *url;
|
char *url;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
unsigned int i, count;
|
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);
|
count = prop_array_count(files_keys);
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
rv = match_files_by_pattern(pkg_filesd,
|
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)
|
if (rv == -1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -122,8 +134,18 @@ find_files_in_package(struct repository_pool_index *rpi, void *arg, bool *done)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
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,
|
struct ffdata *ffd;
|
||||||
__UNCONST(pattern));
|
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;
|
||||||
}
|
}
|
||||||
|
@ -225,10 +225,10 @@ main(int argc, char **argv)
|
|||||||
prop_object_release(pkgd);
|
prop_object_release(pkgd);
|
||||||
} else if (strcasecmp(argv[0], "find-files") == 0) {
|
} else if (strcasecmp(argv[0], "find-files") == 0) {
|
||||||
/* Finds files by patterns, exact matches and components. */
|
/* Finds files by patterns, exact matches and components. */
|
||||||
if (argc != 2)
|
if (argc < 2)
|
||||||
usage(xhp);
|
usage(xhp);
|
||||||
|
|
||||||
rv = repo_find_files_in_packages(argv[1]);
|
rv = repo_find_files_in_packages(argc, argv);
|
||||||
if (rv == ENOTSUP) {
|
if (rv == ENOTSUP) {
|
||||||
xbps_error_printf("xbps-repo: no repositories "
|
xbps_error_printf("xbps-repo: no repositories "
|
||||||
"currently registered!\n");
|
"currently registered!\n");
|
||||||
|
@ -58,6 +58,7 @@ Please note that all targets are case insensitive.
|
|||||||
Prints the name of
|
Prints the name of
|
||||||
.Em package(s)
|
.Em package(s)
|
||||||
matching the pattern on its file list by looking in all repositories index files.
|
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
|
.It Sy genindex Pa /path/to/local/repo
|
||||||
Generates a package index for a local repository as specified in its argument.
|
Generates a package index for a local repository as specified in its argument.
|
||||||
It will look for archives with the
|
It will look for archives with the
|
||||||
|
Loading…
Reference in New Issue
Block a user