Move functionality to resolve revdeps from repos to libxbps.
This commit is contained in:
146
lib/repo.c
146
lib/repo.c
@@ -189,3 +189,149 @@ xbps_repo_get_pkg(struct xbps_repo *repo, const char *pkg)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static prop_array_t
|
||||
revdeps_match(struct xbps_repo *repo, prop_dictionary_t tpkgd, const char *str)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
prop_array_t revdeps = NULL, pkgdeps, provides;
|
||||
prop_object_iterator_t iter;
|
||||
prop_object_t obj;
|
||||
const char *pkgver, *tpkgver, *arch, *vpkg;
|
||||
char *buf;
|
||||
unsigned int i;
|
||||
|
||||
iter = prop_dictionary_iterator(repo->idx);
|
||||
assert(iter);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
pkgd = prop_dictionary_get_keysym(repo->idx, obj);
|
||||
if (prop_dictionary_equals(pkgd, tpkgd))
|
||||
continue;
|
||||
|
||||
pkgdeps = prop_dictionary_get(pkgd, "run_depends");
|
||||
if (pkgdeps == NULL || !prop_array_count(pkgdeps))
|
||||
continue;
|
||||
/*
|
||||
* Try to match passed in string.
|
||||
*/
|
||||
if (str) {
|
||||
if (!xbps_match_pkgdep_in_array(pkgdeps, str))
|
||||
continue;
|
||||
prop_dictionary_get_cstring_nocopy(pkgd,
|
||||
"architecture", &arch);
|
||||
if (!xbps_pkg_arch_match(repo->xhp, arch, NULL))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd,
|
||||
"pkgver", &tpkgver);
|
||||
/* match */
|
||||
if (revdeps == NULL)
|
||||
revdeps = prop_array_create();
|
||||
|
||||
if (!xbps_match_string_in_array(revdeps, tpkgver))
|
||||
prop_array_add_cstring_nocopy(revdeps, tpkgver);
|
||||
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* Try to match any virtual package.
|
||||
*/
|
||||
provides = prop_dictionary_get(tpkgd, "provides");
|
||||
for (i = 0; i < prop_array_count(provides); i++) {
|
||||
prop_array_get_cstring_nocopy(provides, i, &vpkg);
|
||||
if (strchr(vpkg, '_') == NULL)
|
||||
buf = xbps_xasprintf("%s_1", vpkg);
|
||||
else
|
||||
buf = strdup(vpkg);
|
||||
|
||||
if (!xbps_match_pkgdep_in_array(pkgdeps, buf)) {
|
||||
free(buf);
|
||||
continue;
|
||||
}
|
||||
free(buf);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd,
|
||||
"architecture", &arch);
|
||||
if (!xbps_pkg_arch_match(repo->xhp, arch, NULL))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver",
|
||||
&tpkgver);
|
||||
/* match */
|
||||
if (revdeps == NULL)
|
||||
revdeps = prop_array_create();
|
||||
|
||||
if (!xbps_match_string_in_array(revdeps, tpkgver))
|
||||
prop_array_add_cstring_nocopy(revdeps, tpkgver);
|
||||
}
|
||||
/*
|
||||
* Try to match by pkgver.
|
||||
*/
|
||||
prop_dictionary_get_cstring_nocopy(tpkgd, "pkgver", &pkgver);
|
||||
if (!xbps_match_pkgdep_in_array(pkgdeps, pkgver))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd,
|
||||
"architecture", &arch);
|
||||
if (!xbps_pkg_arch_match(repo->xhp, arch, NULL))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &tpkgver);
|
||||
/* match */
|
||||
if (revdeps == NULL)
|
||||
revdeps = prop_array_create();
|
||||
|
||||
if (!xbps_match_string_in_array(revdeps, tpkgver))
|
||||
prop_array_add_cstring_nocopy(revdeps, tpkgver);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
return revdeps;
|
||||
}
|
||||
|
||||
prop_array_t
|
||||
xbps_repo_get_pkg_revdeps(struct xbps_repo *repo, const char *pkg)
|
||||
{
|
||||
prop_array_t revdeps = NULL, vdeps = NULL;
|
||||
prop_dictionary_t pkgd;
|
||||
const char *vpkg;
|
||||
char *buf = NULL;
|
||||
unsigned int i;
|
||||
|
||||
if (((pkgd = xbps_rpool_get_pkg(repo->xhp, pkg)) == NULL) &&
|
||||
((pkgd = xbps_rpool_get_virtualpkg(repo->xhp, pkg)) == NULL)) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
* If pkg is a virtual pkg let's match it instead of the real pkgver.
|
||||
*/
|
||||
if ((vdeps = prop_dictionary_get(pkgd, "provides"))) {
|
||||
for (i = 0; i < prop_array_count(vdeps); i++) {
|
||||
char *vpkgn;
|
||||
|
||||
prop_array_get_cstring_nocopy(vdeps, i, &vpkg);
|
||||
if (strchr(vpkg, '_') == NULL)
|
||||
buf = xbps_xasprintf("%s_1", vpkg);
|
||||
else
|
||||
buf = strdup(vpkg);
|
||||
|
||||
vpkgn = xbps_pkg_name(buf);
|
||||
assert(vpkgn);
|
||||
if (strcmp(vpkgn, pkg) == 0) {
|
||||
free(vpkgn);
|
||||
break;
|
||||
}
|
||||
free(vpkgn);
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
if (buf) {
|
||||
revdeps = revdeps_match(repo, pkgd, buf);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
if (!prop_array_count(revdeps))
|
||||
revdeps = revdeps_match(repo, pkgd, NULL);
|
||||
|
||||
return revdeps;
|
||||
}
|
||||
|
@@ -37,6 +37,7 @@
|
||||
* @defgroup repopool Repository pool functions
|
||||
*/
|
||||
struct rpool_fpkg {
|
||||
prop_array_t revdeps;
|
||||
prop_dictionary_t pkgd;
|
||||
const char *pattern;
|
||||
const char *bestpkgver;
|
||||
@@ -73,6 +74,30 @@ find_pkg_cb(struct xbps_repo *repo, void *arg, bool *done)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
find_pkg_revdeps_cb(struct xbps_repo *repo, void *arg, bool *done)
|
||||
{
|
||||
struct rpool_fpkg *rpf = arg;
|
||||
prop_array_t revdeps = NULL;
|
||||
const char *pkgver;
|
||||
unsigned int i;
|
||||
|
||||
(void)done;
|
||||
|
||||
revdeps = xbps_repo_get_pkg_revdeps(repo, rpf->pattern);
|
||||
if (prop_array_count(revdeps)) {
|
||||
/* found */
|
||||
if (rpf->revdeps == NULL)
|
||||
rpf->revdeps = prop_array_create();
|
||||
for (i = 0; i < prop_array_count(revdeps); i++) {
|
||||
prop_array_get_cstring_nocopy(revdeps, i, &pkgver);
|
||||
prop_array_add_cstring_nocopy(rpf->revdeps, pkgver);
|
||||
}
|
||||
prop_object_release(revdeps);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
find_best_pkg_cb(struct xbps_repo *repo, void *arg, bool *done)
|
||||
{
|
||||
@@ -123,10 +148,11 @@ find_best_pkg_cb(struct xbps_repo *repo, void *arg, bool *done)
|
||||
typedef enum {
|
||||
BEST_PKG = 1,
|
||||
VIRTUAL_PKG,
|
||||
REAL_PKG
|
||||
REAL_PKG,
|
||||
REVDEPS_PKG
|
||||
} pkg_repo_type_t;
|
||||
|
||||
static prop_dictionary_t
|
||||
static prop_object_t
|
||||
repo_find_pkg(struct xbps_handle *xhp,
|
||||
const char *pkg,
|
||||
pkg_repo_type_t type)
|
||||
@@ -136,6 +162,7 @@ repo_find_pkg(struct xbps_handle *xhp,
|
||||
|
||||
rpf.pattern = pkg;
|
||||
rpf.pkgd = NULL;
|
||||
rpf.revdeps = NULL;
|
||||
rpf.bestpkgver = NULL;
|
||||
|
||||
switch (type) {
|
||||
@@ -157,11 +184,18 @@ repo_find_pkg(struct xbps_handle *xhp,
|
||||
*/
|
||||
rv = xbps_rpool_foreach(xhp, find_pkg_cb, &rpf);
|
||||
break;
|
||||
case REVDEPS_PKG:
|
||||
/*
|
||||
* Find revdeps for pkg.
|
||||
*/
|
||||
rv = xbps_rpool_foreach(xhp, find_pkg_revdeps_cb, &rpf);
|
||||
}
|
||||
if (rv != 0) {
|
||||
errno = rv;
|
||||
return NULL;
|
||||
}
|
||||
if (type == REVDEPS_PKG)
|
||||
return rpf.revdeps;
|
||||
|
||||
return rpf.pkgd;
|
||||
}
|
||||
@@ -187,6 +221,15 @@ xbps_rpool_get_pkg(struct xbps_handle *xhp, const char *pkg)
|
||||
return repo_find_pkg(xhp, pkg, REAL_PKG);
|
||||
}
|
||||
|
||||
prop_array_t
|
||||
xbps_rpool_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
|
||||
{
|
||||
assert(xhp);
|
||||
assert(pkg);
|
||||
|
||||
return repo_find_pkg(xhp, pkg, REVDEPS_PKG);
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
xbps_rpool_get_pkg_plist(struct xbps_handle *xhp,
|
||||
const char *pkg,
|
||||
|
Reference in New Issue
Block a user