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

This commit is contained in:
Juan RP 2011-12-22 10:45:13 +01:00
parent 13331f801c
commit d4278be914
5 changed files with 26 additions and 15 deletions

7
NEWS
View File

@ -1,11 +1,14 @@
xbps-0.11.1 (???): xbps-0.11.1 (???):
* libxbps: more paranoid type checking and allocation results, to make * xbps-bin(8): the 'find-files' target accepts multiple patterns, such as:
sure that out of memory conditions are handled gracefully. $ xbps-bin find-files /bin/cat '/bin/f*' ...
* xbps-repo(8): the 'search' target accepts multiple patterns, such as: * xbps-repo(8): the 'search' target accepts multiple patterns, such as:
$ xbps-repo search 'foo-[0-9]*' '*blah*' ... $ xbps-repo search 'foo-[0-9]*' '*blah*' ...
* libxbps: more paranoid type checking and allocation results, to make
sure that out of memory conditions are handled gracefully.
xbps-0.11.0 (2011-12-20): xbps-0.11.0 (2011-12-20):
* xbps-bin(8): it is possible now to reinstall a package even if it's * xbps-bin(8): it is possible now to reinstall a package even if it's

View File

@ -80,7 +80,7 @@ int show_pkg_files_from_metadir(const char *);
int show_orphans(void); int show_orphans(void);
/* from find-files.c */ /* from find-files.c */
int find_files_in_packages(const char *); int find_files_in_packages(int, char **);
/* from question.c */ /* from question.c */
bool yesno(const char *, ...); bool yesno(const char *, ...);

View File

@ -36,13 +36,17 @@
#include "defs.h" #include "defs.h"
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 *pkgname) prop_dictionary_keysym_t key,
int npatterns,
char **patterns,
const char *pkgname)
{ {
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);
@ -59,9 +63,11 @@ 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 < npatterns; i++) {
(xbps_pkgpattern_match(filestr, pattern) == 1)) if ((strcmp(filestr, patterns[i]) == 0) ||
printf("%s: %s (%s)\n", pkgname, filestr, typestr); (xbps_pkgpattern_match(filestr, patterns[i]) == 1))
printf("%s: %s (%s)\n", pkgname, filestr, typestr);
}
} }
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
@ -69,7 +75,7 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd, prop_dictionary_keysym_t ke
} }
int int
find_files_in_packages(const char *pattern) find_files_in_packages(int npatterns, char **patterns)
{ {
struct xbps_handle *xhp; struct xbps_handle *xhp;
prop_dictionary_t pkg_filesd; prop_dictionary_t pkg_filesd;
@ -107,7 +113,8 @@ find_files_in_packages(const char *pattern)
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, dp->d_name); prop_array_get(files_keys, i),
npatterns, patterns, dp->d_name);
if (rv == -1) if (rv == -1)
break; break;
} }

View File

@ -385,10 +385,10 @@ main(int argc, char **argv)
* Find files matched by a pattern from installed * Find files matched by a pattern from installed
* packages. * packages.
*/ */
if (argc != 2) if (argc < 2)
usage(xhp); usage(xhp);
rv = find_files_in_packages(argv[1]); rv = find_files_in_packages(argc, argv);
} else { } else {
usage(xhp); usage(xhp);

View File

@ -1,4 +1,4 @@
.Dd December 20, 2011 .Dd December 22, 2011
.Os Void GNU/Linux .Os Void GNU/Linux
.Dt xbps-bin 8 .Dt xbps-bin 8
.Sh NAME .Sh NAME
@ -144,10 +144,11 @@ Checks for integrity errors in installed packages. The checks are to found
missing run-time dependencies, missing and modified package files and missing run-time dependencies, missing and modified package files and
metadata files. If the all keyword is used, all packages currently installed metadata files. If the all keyword is used, all packages currently installed
will be checked, otherwise just pkgname. will be checked, otherwise just pkgname.
.It Sy find-files Ar pattern .It Sy find-files Ar pattern Ar [patterns ...]
Prints the name of the installed Prints the name of the installed
.Em package(s) .Em package(s)
matching the pattern on its file list. matching the pattern on its file list. Multiple patterns can be specified
as arguments.
.It Sy install Ar pkgname(s) | Ar pkgpattern(s) .It Sy install Ar pkgname(s) | Ar pkgpattern(s)
Install binary package(s) from repository pool by specifying Install binary package(s) from repository pool by specifying
.Em pkgname(s) .Em pkgname(s)