libxbps: require a pointer to xbps_handle in functions that need it.

This removes 2 global vars from lib/initend.c and easier to know
what functions require access to xbps_handle.
This commit is contained in:
Juan RP
2012-06-14 08:22:11 +02:00
parent a3adbcda95
commit 3e9e87fc2a
60 changed files with 1143 additions and 901 deletions

View File

@@ -45,10 +45,15 @@ struct repo_pool_fpkg {
};
static int
repo_find_virtualpkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
repo_find_virtualpkg_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
struct repo_pool_fpkg *rpf = arg;
(void)xhp;
if (rpf->bypattern) {
rpf->pkgd =
xbps_find_virtualpkg_in_array_by_pattern(rpi->repo,
@@ -68,18 +73,21 @@ repo_find_virtualpkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
}
static int
repo_find_virtualpkg_conf_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
repo_find_virtualpkg_conf_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
struct repo_pool_fpkg *rpf = arg;
if (rpf->bypattern) {
rpf->pkgd =
xbps_find_virtualpkg_conf_in_array_by_pattern(rpi->repo,
rpf->pattern);
xbps_find_virtualpkg_conf_in_array_by_pattern(xhp,
rpi->repo, rpf->pattern);
} else {
rpf->pkgd =
xbps_find_virtualpkg_conf_in_array_by_name(rpi->repo,
rpf->pattern);
xbps_find_virtualpkg_conf_in_array_by_name(xhp,
rpi->repo, rpf->pattern);
}
if (rpf->pkgd) {
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
@@ -91,10 +99,15 @@ repo_find_virtualpkg_conf_cb(struct xbps_rpool_index *rpi, void *arg, bool *done
}
static int
repo_find_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
repo_find_pkg_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
struct repo_pool_fpkg *rpf = arg;
(void)xhp;
if (rpf->exact) {
/* exact match by pkgver */
rpf->pkgd = xbps_find_pkg_in_array_by_pkgver(rpi->repo,
@@ -122,13 +135,17 @@ repo_find_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
}
static int
repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
repo_find_best_pkg_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
struct repo_pool_fpkg *rpf = arg;
const char *repopkgver;
prop_dictionary_t pkgd;
(void)done;
(void)xhp;
if (rpf->bypattern) {
pkgd = xbps_find_pkg_in_array_by_pattern(rpi->repo,
@@ -141,14 +158,16 @@ repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
if (errno && errno != ENOENT)
return errno;
xbps_dbg_printf("[rpool] Package '%s' not found in repository "
xbps_dbg_printf(xhp,
"[rpool] Package '%s' not found in repository "
"'%s'.\n", rpf->pattern, rpi->uri);
return 0;
}
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &repopkgver);
if (rpf->bestpkgver == NULL) {
xbps_dbg_printf("[rpool] Found best match '%s' (%s).\n",
xbps_dbg_printf(xhp,
"[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri);
rpf->pkgd = pkgd;
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
@@ -160,7 +179,8 @@ repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
* version from current package in repository.
*/
if (xbps_cmpver(repopkgver, rpf->bestpkgver) == 1) {
xbps_dbg_printf("[rpool] Found best match '%s' (%s).\n",
xbps_dbg_printf(xhp,
"[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri);
rpf->pkgd = pkgd;
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
@@ -178,7 +198,10 @@ typedef enum {
} pkg_repo_type_t;
static prop_dictionary_t
repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type)
repo_find_pkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
pkg_repo_type_t type)
{
struct repo_pool_fpkg rpf;
int rv = 0;
@@ -195,31 +218,31 @@ repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type)
* Find exact pkg version.
*/
rpf.exact = true;
rv = xbps_rpool_foreach(repo_find_pkg_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_pkg_cb, &rpf);
break;
case BEST_PKG:
/*
* Find best pkg version.
*/
rv = xbps_rpool_foreach(repo_find_best_pkg_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_best_pkg_cb, &rpf);
break;
case VIRTUAL_PKG:
/*
* Find virtual pkg.
*/
rv = xbps_rpool_foreach(repo_find_virtualpkg_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_virtualpkg_cb, &rpf);
break;
case VIRTUAL_CONF_PKG:
/*
* Find virtual pkg as specified in configuration file.
*/
rv = xbps_rpool_foreach(repo_find_virtualpkg_conf_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_virtualpkg_conf_cb, &rpf);
break;
case REAL_PKG:
/*
* Find real pkg.
*/
rv = xbps_rpool_foreach(repo_find_pkg_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_pkg_cb, &rpf);
break;
}
if (rv != 0) {
@@ -231,42 +254,51 @@ repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type)
}
prop_dictionary_t
xbps_rpool_find_virtualpkg(const char *pkg, bool bypattern)
xbps_rpool_find_virtualpkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern)
{
assert(pkg != NULL);
return repo_find_pkg(pkg, bypattern, VIRTUAL_PKG);
return repo_find_pkg(xhp, pkg, bypattern, VIRTUAL_PKG);
}
prop_dictionary_t
xbps_rpool_find_virtualpkg_conf(const char *pkg, bool bypattern)
xbps_rpool_find_virtualpkg_conf(struct xbps_handle *xhp,
const char *pkg,
bool bypattern)
{
assert(pkg != NULL);
return repo_find_pkg(pkg, bypattern, VIRTUAL_CONF_PKG);
return repo_find_pkg(xhp, pkg, bypattern, VIRTUAL_CONF_PKG);
}
prop_dictionary_t
xbps_rpool_find_pkg(const char *pkg, bool bypattern, bool best)
xbps_rpool_find_pkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
bool best)
{
assert(pkg != NULL);
if (best)
return repo_find_pkg(pkg, bypattern, BEST_PKG);
return repo_find_pkg(xhp, pkg, bypattern, BEST_PKG);
return repo_find_pkg(pkg, bypattern, REAL_PKG);
return repo_find_pkg(xhp, pkg, bypattern, REAL_PKG);
}
prop_dictionary_t
xbps_rpool_find_pkg_exact(const char *pkgver)
xbps_rpool_find_pkg_exact(struct xbps_handle *xhp, const char *pkgver)
{
assert(pkgver != NULL);
return repo_find_pkg(pkgver, false, EXACT_PKG);
return repo_find_pkg(xhp, pkgver, false, EXACT_PKG);
}
prop_dictionary_t
xbps_rpool_dictionary_metadata_plist(const char *pattern, const char *plistf)
xbps_rpool_dictionary_metadata_plist(struct xbps_handle *xhp,
const char *pattern,
const char *plistf)
{
prop_dictionary_t pkgd = NULL, plistd = NULL;
const char *repoloc;
@@ -284,15 +316,15 @@ xbps_rpool_dictionary_metadata_plist(const char *pattern, const char *plistf)
* libfetch!
*/
if (xbps_pkgpattern_version(pattern))
pkgd = xbps_rpool_find_pkg(pattern, true, false);
pkgd = xbps_rpool_find_pkg(xhp, pattern, true, false);
else
pkgd = xbps_rpool_find_pkg(pattern, false, true);
pkgd = xbps_rpool_find_pkg(xhp, pattern, false, true);
if (pkgd == NULL)
goto out;
prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repoloc);
url = xbps_path_from_repository_uri(pkgd, repoloc);
url = xbps_path_from_repository_uri(xhp, pkgd, repoloc);
if (url == NULL) {
errno = EINVAL;
goto out;