2010-12-15 19:44:44 +05:30
|
|
|
/*-
|
|
|
|
* Copyright (c) 2010 Juan Romero Pardines.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <xbps_api.h>
|
|
|
|
#include "defs.h"
|
|
|
|
|
2011-12-22 15:31:28 +05:30
|
|
|
struct ffdata {
|
|
|
|
int npatterns;
|
|
|
|
char **patterns;
|
|
|
|
};
|
|
|
|
|
2010-12-15 19:44:44 +05:30
|
|
|
static int
|
2011-12-22 15:31:28 +05:30
|
|
|
match_files_by_pattern(prop_dictionary_t pkg_filesd,
|
|
|
|
prop_dictionary_keysym_t key,
|
|
|
|
struct ffdata *ffd,
|
|
|
|
const char *pkgver)
|
2010-12-15 19:44:44 +05:30
|
|
|
{
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
prop_array_t array;
|
|
|
|
prop_object_t obj;
|
|
|
|
const char *keyname, *filestr, *typestr;
|
2011-12-22 15:31:28 +05:30
|
|
|
int i;
|
2010-12-15 19:44:44 +05:30
|
|
|
|
|
|
|
keyname = prop_dictionary_keysym_cstring_nocopy(key);
|
|
|
|
array = prop_dictionary_get_keysym(pkg_filesd, key);
|
|
|
|
if (prop_object_type(array) != PROP_TYPE_ARRAY)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (strcmp(keyname, "files") == 0)
|
|
|
|
typestr = "regular file";
|
|
|
|
else if (strcmp(keyname, "dirs") == 0)
|
|
|
|
typestr = "directory";
|
|
|
|
else if (strcmp(keyname, "links") == 0)
|
|
|
|
typestr = "link";
|
|
|
|
else
|
|
|
|
typestr = "configuration file";
|
|
|
|
|
|
|
|
iter = prop_array_iterator(array);
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "file", &filestr);
|
2011-12-22 15:31:28 +05:30
|
|
|
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);
|
|
|
|
}
|
2010-12-15 19:44:44 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_files_in_package(struct repository_pool_index *rpi, void *arg, bool *done)
|
|
|
|
{
|
|
|
|
prop_dictionary_t pkg_filesd;
|
2011-01-20 21:11:49 +05:30
|
|
|
prop_array_t files_keys;
|
2010-12-15 19:44:44 +05:30
|
|
|
prop_object_t obj;
|
|
|
|
prop_object_iterator_t iter;
|
2011-12-22 15:31:28 +05:30
|
|
|
struct ffdata *ffd = arg;
|
|
|
|
const char *pkgname, *pkgver;
|
2010-12-15 19:44:44 +05:30
|
|
|
char *url;
|
|
|
|
int rv = 0;
|
|
|
|
unsigned int i, count;
|
|
|
|
|
|
|
|
(void)done;
|
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
iter = xbps_array_iter_from_dict(rpi->rpi_repod, "packages");
|
2010-12-15 19:44:44 +05:30
|
|
|
if (iter == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
printf("Looking in repository '%s', please wait...\n", rpi->rpi_uri);
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
2011-06-01 13:07:32 +05:30
|
|
|
url = xbps_path_from_repository_uri(obj, rpi->rpi_uri);
|
2010-12-15 19:44:44 +05:30
|
|
|
if (url == NULL) {
|
|
|
|
rv = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
2011-06-01 13:07:32 +05:30
|
|
|
pkg_filesd = xbps_dictionary_metadata_plist_by_url(url,
|
2010-12-15 19:44:44 +05:30
|
|
|
XBPS_PKGFILES);
|
|
|
|
free(url);
|
|
|
|
if (pkg_filesd == NULL) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-repo: couldn't read '%s' "
|
|
|
|
"from '%s (%s)': %s\n", XBPS_PKGFILES, pkgname,
|
|
|
|
rpi->rpi_uri, strerror(errno));
|
2010-12-15 19:44:44 +05:30
|
|
|
rv = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
files_keys = prop_dictionary_all_keys(pkg_filesd);
|
|
|
|
count = prop_array_count(files_keys);
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
rv = match_files_by_pattern(pkg_filesd,
|
2011-12-22 15:31:28 +05:30
|
|
|
prop_array_get(files_keys, i), ffd, pkgver);
|
2010-12-15 19:44:44 +05:30
|
|
|
if (rv == -1)
|
|
|
|
break;
|
|
|
|
}
|
2010-12-24 09:51:49 +05:30
|
|
|
prop_object_release(files_keys);
|
2010-12-15 19:44:44 +05:30
|
|
|
prop_object_release(pkg_filesd);
|
|
|
|
if (rv == -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-12-22 15:31:28 +05:30
|
|
|
repo_find_files_in_packages(int npatterns, char **patterns)
|
2010-12-15 19:44:44 +05:30
|
|
|
{
|
2011-12-22 15:31:28 +05:30
|
|
|
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;
|
2010-12-15 19:44:44 +05:30
|
|
|
}
|