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

@ -31,12 +31,12 @@
#include "xbps_api_impl.h"
static int
store_dependency(prop_array_t transd_unsorted,
store_dependency(struct xbps_handle *xhp,
prop_dictionary_t repo_pkgd,
pkg_state_t repo_pkg_state,
size_t *depth)
{
const struct xbps_handle *xhp = xbps_handle_get();
prop_array_t unsorted;
int rv;
/*
* Overwrite package state in dictionary with same state than the
@ -52,7 +52,8 @@ store_dependency(prop_array_t transd_unsorted,
/*
* Add the dictionary into the array.
*/
if (!prop_array_add(transd_unsorted, repo_pkgd))
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (!prop_array_add(unsorted, repo_pkgd))
return EINVAL;
if (xhp->flags & XBPS_FLAG_DEBUG) {
@ -63,19 +64,20 @@ store_dependency(prop_array_t transd_unsorted,
"repository", &repo);
prop_dictionary_get_cstring_nocopy(repo_pkgd,
"pkgver", &pkgver);
xbps_dbg_printf(" ");
xbps_dbg_printf(xhp, " ");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");
xbps_dbg_printf_append(xhp, " ");
xbps_dbg_printf_append("%s: added into "
xbps_dbg_printf_append(xhp, "%s: added into "
"the transaction (%s).\n", pkgver, repo);
}
return 0;
}
static int
add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg)
add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
{
prop_array_t mdeps;
prop_string_t reqpkg_str;
prop_object_iterator_t iter = NULL;
prop_object_t obj;
@ -83,16 +85,16 @@ add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg)
bool add_pkgdep, pkgfound, update_pkgdep;
int rv = 0;
assert(prop_object_type(missing_rdeps) == PROP_TYPE_ARRAY);
assert(reqpkg != NULL);
add_pkgdep = update_pkgdep = pkgfound = false;
mdeps = prop_dictionary_get(xhp->transd, "missing_deps");
reqpkg_str = prop_string_create_cstring_nocopy(reqpkg);
if (reqpkg_str == NULL)
return errno;
iter = prop_array_iterator(missing_rdeps);
iter = prop_array_iterator(mdeps);
if (iter == NULL)
goto out;
@ -126,7 +128,7 @@ add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg)
* if new dependency version is greater than current
* one, store it.
*/
xbps_dbg_printf("Missing pkgdep name matched, "
xbps_dbg_printf(xhp, "Missing pkgdep name matched, "
"curver: %s newver: %s\n", curver, pkgver);
if (xbps_cmpver(curver, pkgver) <= 0) {
add_pkgdep = false;
@ -149,8 +151,8 @@ out:
if (iter)
prop_object_iterator_release(iter);
if (update_pkgdep)
prop_array_remove(missing_rdeps, idx);
if (add_pkgdep && !xbps_add_obj_to_array(missing_rdeps, reqpkg_str)) {
prop_array_remove(mdeps, idx);
if (add_pkgdep && !xbps_add_obj_to_array(mdeps, reqpkg_str)) {
prop_object_release(reqpkg_str);
return errno;
}
@ -161,13 +163,11 @@ out:
#define MAX_DEPTH 512
static int
find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
prop_array_t trans_mdeps, /* transaction missing deps array */
find_repo_deps(struct xbps_handle *xhp,
prop_array_t pkg_rdeps_array, /* current pkg rundeps array */
const char *curpkg, /* current pkgver */
size_t *depth) /* max recursion depth */
{
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t curpkgd, tmpd;
prop_array_t curpkgrdeps, unsorted;
pkg_state_t state;
@ -186,11 +186,11 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
for (i = 0; i < prop_array_count(pkg_rdeps_array); i++) {
prop_array_get_cstring_nocopy(pkg_rdeps_array, i, &reqpkg);
if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf("");
xbps_dbg_printf(xhp, "");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");
xbps_dbg_printf_append("%s: requires dependency '%s': ",
curpkg ? curpkg : " ", reqpkg);
xbps_dbg_printf_append(xhp, " ");
xbps_dbg_printf_append(xhp, "%s: requires dependency '%s': ",
curpkg != NULL ? curpkg : " ", reqpkg);
}
/*
* Pass 1: check if required dependency is already installed
@ -198,19 +198,19 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
*/
if ((pkgname = xbps_pkgpattern_name(reqpkg)) == NULL) {
rv = EINVAL;
xbps_dbg_printf("failed to get "
xbps_dbg_printf(xhp, "failed to get "
"pkgname from `%s'!", reqpkg);
break;
}
/*
* Look for a real package installed...
*/
tmpd = xbps_find_pkg_dict_installed(pkgname, false);
tmpd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
if (tmpd == NULL) {
if (errno && errno != ENOENT) {
/* error */
rv = errno;
xbps_dbg_printf("failed to find "
xbps_dbg_printf(xhp, "failed to find "
"installed pkg for `%s': %s\n",
reqpkg, strerror(errno));
break;
@ -219,20 +219,21 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* real package not installed, try looking for
* a virtual package instead.
*/
tmpd = xbps_find_virtualpkg_dict_installed(pkgname, false);
tmpd = xbps_find_virtualpkg_dict_installed(xhp,
pkgname, false);
}
free(pkgname);
if (tmpd == NULL) {
if (errno && errno != ENOENT) {
/* error */
rv = errno;
xbps_dbg_printf("failed to find "
xbps_dbg_printf(xhp, "failed to find "
"installed virtual pkg for `%s': %s\n",
reqpkg, strerror(errno));
break;
}
/* Required pkgdep not installed */
xbps_dbg_printf_append("not installed. ");
xbps_dbg_printf_append(xhp, "not installed. ");
reason = "install";
state = XBPS_PKG_STATE_NOT_INSTALLED;
} else {
@ -255,7 +256,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* package and is satisfied by an
* installed package.
*/
xbps_dbg_printf_append("[virtual] satisfied by "
xbps_dbg_printf_append(xhp,
"[virtual] satisfied by "
"`%s'.\n", pkgver_q);
prop_object_release(tmpd);
continue;
@ -266,7 +268,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Package is installed but does not match
* the dependency pattern, update pkg.
*/
xbps_dbg_printf_append("installed `%s', "
xbps_dbg_printf_append(xhp,
"installed `%s', "
"must be updated.\n", pkgver_q);
reason = "update";
} else if (rv == 1) {
@ -277,7 +280,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* pattern but was only unpacked,
* configure pkg.
*/
xbps_dbg_printf_append("installed `%s'"
xbps_dbg_printf_append(xhp,
"installed `%s'"
", must be configured.\n",
pkgver_q);
reason = "configure";
@ -287,7 +291,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* pattern and is fully installed,
* skip to next one.
*/
xbps_dbg_printf_append("installed "
xbps_dbg_printf_append(xhp,
"installed "
"`%s'.\n", pkgver_q);
prop_object_release(tmpd);
continue;
@ -295,7 +300,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
} else {
/* error matching pkgpattern */
prop_object_release(tmpd);
xbps_dbg_printf("failed to match "
xbps_dbg_printf(xhp, "failed to match "
"pattern %s with %s\n", reqpkg, pkgver_q);
break;
}
@ -304,9 +309,9 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Pass 2: check if required dependency has been already
* added in the transaction dictionary.
*/
unsorted = prop_dictionary_get(transd, "unsorted_deps");
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (((curpkgd = xbps_find_pkg_in_array_by_pattern(unsorted, reqpkg, NULL)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(unsorted, reqpkg)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(xhp, unsorted, reqpkg)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_in_array_by_pattern(unsorted, reqpkg)) == NULL)) {
/* error matching required pkgdep */
if (errno && errno != ENOENT) {
@ -316,7 +321,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
} else {
prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
xbps_dbg_printf_append(" (%s queued "
xbps_dbg_printf_append(xhp, " (%s queued "
"in transaction).\n", pkgver_q);
continue;
}
@ -325,35 +330,37 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* If dependency does not match add pkg into the missing
* deps array and pass to next one.
*/
if (((curpkgd = xbps_rpool_find_virtualpkg_conf(reqpkg, true)) == NULL) &&
((curpkgd = xbps_rpool_find_pkg(reqpkg, true, true)) == NULL) &&
((curpkgd = xbps_rpool_find_virtualpkg(reqpkg, true)) == NULL)) {
if (((curpkgd = xbps_rpool_find_virtualpkg_conf(xhp, reqpkg, true)) == NULL) &&
((curpkgd = xbps_rpool_find_pkg(xhp, reqpkg, true, true)) == NULL) &&
((curpkgd = xbps_rpool_find_virtualpkg(xhp, reqpkg, true)) == NULL)) {
/* pkg not found, there was some error */
if (errno && errno != ENOENT) {
xbps_dbg_printf("failed to find pkg "
xbps_dbg_printf(xhp, "failed to find pkg "
"for `%s' in rpool: %s\n",
reqpkg, strerror(errno));
rv = errno;
break;
}
rv = add_missing_reqdep(trans_mdeps, reqpkg);
rv = add_missing_reqdep(xhp, reqpkg);
if (rv != 0 && rv != EEXIST) {
xbps_dbg_printf_append("`%s': "
xbps_dbg_printf_append(xhp, "`%s': "
"add_missing_reqdep failed %s\n",
reqpkg);
break;
} else if (rv == EEXIST) {
xbps_dbg_printf_append("`%s' missing "
xbps_dbg_printf_append(xhp, "`%s' missing "
"dep already added.\n", reqpkg);
rv = 0;
continue;
} else {
xbps_dbg_printf_append("`%s' added "
xbps_dbg_printf_append(xhp, "`%s' added "
"into the missing deps array.\n",
reqpkg);
continue;
}
}
prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
/*
* Check if package has matched conflicts.
*/
@ -362,9 +369,9 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Package is on repo, add it into the transaction dictionary.
*/
prop_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason);
rv = store_dependency(unsorted, curpkgd, state, depth);
rv = store_dependency(xhp, curpkgd, state, depth);
if (rv != 0) {
xbps_dbg_printf("store_dependency failed for "
xbps_dbg_printf(xhp, "store_dependency failed for "
"`%s': %s\n", reqpkg, strerror(rv));
prop_object_release(curpkgd);
break;
@ -379,21 +386,20 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
}
prop_object_release(curpkgd);
if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf("");
xbps_dbg_printf(xhp, "");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");
xbps_dbg_printf_append(xhp, " ");
xbps_dbg_printf_append(" %s: finding dependencies:\n",
pkgver_q);
xbps_dbg_printf_append(xhp,
"%s: finding dependencies:\n", pkgver_q);
}
/*
* Recursively find rundeps for current pkg dictionary.
*/
(*depth)++;
rv = find_repo_deps(transd, trans_mdeps, curpkgrdeps,
pkgver_q, depth);
rv = find_repo_deps(xhp, curpkgrdeps, pkgver_q, depth);
if (rv != 0) {
xbps_dbg_printf("Error checking %s for rundeps: %s\n",
xbps_dbg_printf(xhp, "Error checking %s for rundeps: %s\n",
reqpkg, strerror(rv));
break;
}
@ -407,7 +413,7 @@ int HIDDEN
xbps_repository_find_pkg_deps(struct xbps_handle *xhp,
prop_dictionary_t repo_pkgd)
{
prop_array_t mdeps, pkg_rdeps;
prop_array_t pkg_rdeps;
const char *pkgver;
size_t depth = 0;
@ -416,11 +422,10 @@ xbps_repository_find_pkg_deps(struct xbps_handle *xhp,
return 0;
prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver);
xbps_dbg_printf("Finding required dependencies for '%s':\n", pkgver);
mdeps = prop_dictionary_get(xhp->transd, "missing_deps");
xbps_dbg_printf(xhp, "Finding required dependencies for '%s':\n", pkgver);
/*
* This will find direct and indirect deps, if any of them is not
* there it will be added into the missing_deps array.
*/
return find_repo_deps(xhp->transd, mdeps, pkg_rdeps, pkgver, &depth);
return find_repo_deps(xhp, pkg_rdeps, pkgver, &depth);
}