2010-12-15 19:44:44 +05:30
|
|
|
/*-
|
2012-01-15 18:54:44 +05:30
|
|
|
* Copyright (c) 2010-2012 Juan Romero Pardines.
|
2010-12-15 19:44:44 +05:30
|
|
|
* 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;
|
2012-05-31 19:59:56 +05:30
|
|
|
const char *repouri;
|
2011-12-22 15:31:28 +05:30
|
|
|
};
|
|
|
|
|
2012-01-15 18:54:44 +05:30
|
|
|
static void
|
2012-06-15 19:03:11 +05:30
|
|
|
match_files_by_pattern(struct xbps_handle *xhp,
|
|
|
|
prop_dictionary_t pkg_filesd,
|
|
|
|
struct ffdata *ffd)
|
2010-12-15 19:44:44 +05:30
|
|
|
{
|
2012-05-31 19:59:56 +05:30
|
|
|
prop_array_t array;
|
|
|
|
const char *filestr, *pkgver, *arch;
|
2012-01-15 18:54:44 +05:30
|
|
|
size_t i;
|
|
|
|
int x;
|
|
|
|
|
2012-05-31 19:59:56 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_filesd, "architecture", &arch);
|
2012-06-15 19:03:11 +05:30
|
|
|
if (!xbps_pkg_arch_match(xhp, arch, NULL))
|
2012-05-31 19:59:56 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
array = prop_dictionary_get(pkg_filesd, "files");
|
|
|
|
for (i = 0; i < prop_array_count(array); i++) {
|
|
|
|
prop_array_get_cstring_nocopy(array, i, &filestr);
|
|
|
|
for (x = 1; x < ffd->npatterns; x++) {
|
|
|
|
if ((xbps_pkgpattern_match(filestr, ffd->patterns[x])) ||
|
|
|
|
(strstr(filestr, ffd->patterns[x]))) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_filesd,
|
|
|
|
"pkgver", &pkgver);
|
|
|
|
printf("%s: %s (%s)\n",
|
|
|
|
pkgver, filestr, ffd->repouri);
|
2012-01-15 18:54:44 +05:30
|
|
|
}
|
2011-12-22 15:31:28 +05:30
|
|
|
}
|
2010-12-15 19:44:44 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
find_files_in_package(struct xbps_handle *xhp,
|
|
|
|
struct xbps_rpool_index *rpi,
|
|
|
|
void *arg,
|
|
|
|
bool *done)
|
2010-12-15 19:44:44 +05:30
|
|
|
{
|
2012-01-15 21:03:44 +05:30
|
|
|
prop_array_t idxfiles;
|
2011-12-22 15:31:28 +05:30
|
|
|
struct ffdata *ffd = arg;
|
2012-01-15 18:54:44 +05:30
|
|
|
char *plist;
|
|
|
|
unsigned int i;
|
2010-12-15 19:44:44 +05:30
|
|
|
|
|
|
|
(void)done;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((plist = xbps_pkg_index_files_plist(xhp, rpi->uri)) == NULL)
|
2012-01-15 18:54:44 +05:30
|
|
|
return ENOMEM;
|
|
|
|
|
2012-05-31 19:59:56 +05:30
|
|
|
if ((idxfiles = prop_array_internalize_from_zfile(plist)) == NULL) {
|
2012-01-15 18:54:44 +05:30
|
|
|
free(plist);
|
2012-06-01 18:32:06 +05:30
|
|
|
if (errno == ENOENT) {
|
|
|
|
fprintf(stderr, "%s: index-files missing! "
|
|
|
|
"ignoring...\n", rpi->uri);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-15 18:54:44 +05:30
|
|
|
return errno;
|
2010-12-15 19:44:44 +05:30
|
|
|
}
|
2012-01-15 18:54:44 +05:30
|
|
|
free(plist);
|
2012-05-31 19:59:56 +05:30
|
|
|
ffd->repouri = rpi->uri;
|
2012-01-15 18:54:44 +05:30
|
|
|
|
2012-01-15 21:03:44 +05:30
|
|
|
for (i = 0; i < prop_array_count(idxfiles); i++)
|
2012-06-15 19:03:11 +05:30
|
|
|
match_files_by_pattern(xhp, prop_array_get(idxfiles, i), ffd);
|
2012-01-15 18:54:44 +05:30
|
|
|
|
2012-01-15 21:03:44 +05:30
|
|
|
prop_object_release(idxfiles);
|
2012-01-15 18:54:44 +05:30
|
|
|
return 0;
|
2010-12-15 19:44:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
repo_find_files_in_packages(struct xbps_handle *xhp,
|
|
|
|
int npatterns,
|
|
|
|
char **patterns)
|
2010-12-15 19:44:44 +05:30
|
|
|
{
|
2012-05-31 19:59:56 +05:30
|
|
|
struct ffdata ffd;
|
2011-12-22 15:31:28 +05:30
|
|
|
|
2012-05-31 19:59:56 +05:30
|
|
|
ffd.npatterns = npatterns;
|
|
|
|
ffd.patterns = patterns;
|
2011-12-22 15:31:28 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
return xbps_rpool_foreach(xhp, find_files_in_package, &ffd);
|
2010-12-15 19:44:44 +05:30
|
|
|
}
|