Use prop iterators when needed to retain the obj.

This could explain the strange issues seen in buildbot builds that
have been happening since 0.18; this should fix completely this.
This commit is contained in:
Juan RP 2012-11-30 09:49:09 +01:00
parent 9715d8a6a1
commit b9136c61c9
8 changed files with 87 additions and 50 deletions

View File

@ -50,20 +50,23 @@ int
xbps_configure_packages(struct xbps_handle *xhp, bool flush)
{
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname;
size_t i;
int rv;
if ((rv = xbps_pkgdb_init(xhp)) != 0)
return rv;
for (i = 0; i < prop_array_count(xhp->pkgdb); i++) {
obj = prop_array_get(xhp->pkgdb, i);
iter = prop_array_iterator(xhp->pkgdb);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
rv = xbps_configure_pkg(xhp, pkgname, true, false, false);
if (rv != 0)
break;
}
prop_object_iterator_release(iter);
if (flush)
rv = xbps_pkgdb_update(xhp, true);

View File

@ -38,9 +38,10 @@ xbps_pkg_find_conflicts(struct xbps_handle *xhp,
{
prop_array_t pkg_cflicts, trans_cflicts;
prop_dictionary_t pkgd;
prop_object_t obj;
prop_object_iterator_t iter;
const char *cfpkg, *repopkgver, *pkgver;
char *buf;
size_t i;
pkg_cflicts = prop_dictionary_get(pkg_repod, "conflicts");
if (pkg_cflicts == NULL || prop_array_count(pkg_cflicts) == 0)
@ -49,8 +50,10 @@ xbps_pkg_find_conflicts(struct xbps_handle *xhp,
trans_cflicts = prop_dictionary_get(xhp->transd, "conflicts");
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver);
for (i = 0; i < prop_array_count(pkg_cflicts); i++) {
prop_array_get_cstring_nocopy(pkg_cflicts, i, &cfpkg);
iter = prop_array_iterator(trans_cflicts);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
cfpkg = prop_string_cstring_nocopy(obj);
/*
* Check if current pkg conflicts with an installed package.
*/
@ -78,4 +81,5 @@ xbps_pkg_find_conflicts(struct xbps_handle *xhp,
continue;
}
}
prop_object_iterator_release(iter);
}

View File

@ -35,12 +35,14 @@ static prop_dictionary_t
get_pkg_in_array(prop_array_t array, const char *str, bool virtual)
{
prop_object_t obj = NULL;
prop_object_iterator_t iter;
const char *pkgver, *dpkgn;
size_t i;
bool found = false;
for (i = 0; i < prop_array_count(array); i++) {
obj = prop_array_get(array, i);
iter = prop_array_iterator(array);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
if (virtual) {
/*
* Check if package pattern matches
@ -82,6 +84,8 @@ get_pkg_in_array(prop_array_t array, const char *str, bool virtual)
}
}
}
prop_object_iterator_release(iter);
return found ? obj : NULL;
}

View File

@ -62,28 +62,40 @@ bool
xbps_match_any_virtualpkg_in_rundeps(prop_array_t rundeps,
prop_array_t provides)
{
prop_object_t obj, obj2;
prop_object_iterator_t iter, iter2;
const char *vpkgver, *pkgpattern;
char *tmp;
size_t i, x;
for (i = 0; i < prop_array_count(provides); i++) {
iter = prop_array_iterator(provides);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
tmp = NULL;
prop_array_get_cstring_nocopy(provides, i, &vpkgver);
vpkgver = prop_string_cstring_nocopy(obj);
if (strchr(vpkgver, '_') == NULL) {
tmp = xbps_xasprintf("%s_1", vpkgver);
vpkgver = tmp;
}
for (x = 0; x < prop_array_count(rundeps); x++) {
prop_array_get_cstring_nocopy(rundeps, x, &pkgpattern);
iter2 = prop_array_iterator(rundeps);
assert(iter2);
while ((obj2 = prop_object_iterator_next(iter2))) {
pkgpattern = prop_string_cstring_nocopy(obj2);
if (xbps_pkgpattern_match(vpkgver, pkgpattern)) {
if (tmp != NULL)
free(tmp);
prop_object_iterator_release(iter2);
prop_object_iterator_release(iter);
return true;
}
}
prop_object_iterator_release(iter2);
if (tmp != NULL)
free(tmp);
}
prop_object_iterator_release(iter);
return false;
}
@ -100,8 +112,7 @@ match_string_in_array(prop_array_t array, const char *str, int mode)
assert(str != NULL);
iter = prop_array_iterator(array);
if (iter == NULL)
return false;
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
tmp = NULL;

View File

@ -142,11 +142,10 @@ vpkg_user_conf(struct xbps_handle *xhp,
prop_dictionary_t
xbps_rindex_get_virtualpkg(struct xbps_rindex *rpi, const char *pkg)
{
prop_array_t allkeys;
prop_dictionary_keysym_t ksym;
prop_object_t obj;
prop_object_iterator_t iter;
prop_dictionary_t pkgd = NULL;
const char *vpkg;
size_t i;
bool found = false, bypattern = false;
if (xbps_pkgpattern_version(pkg))
@ -169,16 +168,17 @@ xbps_rindex_get_virtualpkg(struct xbps_rindex *rpi, const char *pkg)
}
/* ... otherwise match the first one in dictionary */
allkeys = prop_dictionary_all_keys(rpi->repod);
for (i = 0; i < prop_array_count(allkeys); i++) {
ksym = prop_array_get(allkeys, i);
pkgd = prop_dictionary_get_keysym(rpi->repod, ksym);
iter = prop_dictionary_iterator(rpi->repod);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
pkgd = prop_dictionary_get_keysym(rpi->repod, obj);
if (xbps_match_virtual_pkg_in_dict(pkgd, pkg, bypattern)) {
found = true;
break;
}
}
prop_object_release(allkeys);
prop_object_iterator_release(iter);
out:
if (found) {

View File

@ -153,9 +153,11 @@ find_repo_deps(struct xbps_handle *xhp,
size_t *depth) /* max recursion depth */
{
prop_dictionary_t curpkgd, tmpd;
prop_object_t obj;
prop_object_iterator_t iter;
prop_array_t curpkgrdeps;
pkg_state_t state;
size_t i, x;
size_t x;
const char *reqpkg, *pkgver_q, *reason = NULL;
int rv = 0;
@ -166,8 +168,11 @@ find_repo_deps(struct xbps_handle *xhp,
* Iterate over the list of required run dependencies for
* current package.
*/
for (i = 0; i < prop_array_count(pkg_rdeps_array); i++) {
prop_array_get_cstring_nocopy(pkg_rdeps_array, i, &reqpkg);
iter = prop_array_iterator(pkg_rdeps_array);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
reqpkg = prop_string_cstring_nocopy(obj);
if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf(xhp, "");
for (x = 0; x < *depth; x++)
@ -343,6 +348,7 @@ find_repo_deps(struct xbps_handle *xhp,
break;
}
}
prop_object_iterator_release(iter);
(*depth)--;
return rv;

View File

@ -175,16 +175,19 @@ int
xbps_transaction_update_packages(struct xbps_handle *xhp)
{
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname, *holdpkg;
bool foundhold = false, newpkg_found = false;
int rv = 0;
size_t i, x;
size_t x;
if ((rv = xbps_pkgdb_init(xhp)) != 0)
return rv;
for (i = 0; i < prop_array_count(xhp->pkgdb); i++) {
obj = prop_array_get(xhp->pkgdb, i);
iter = prop_array_iterator(xhp->pkgdb);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
for (x = 0; x < cfg_size(xhp->cfg, "PackagesOnHold"); x++) {
@ -212,6 +215,7 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
rv = 0;
}
}
prop_object_iterator_release(iter);
return newpkg_found ? rv : EEXIST;
}

View File

@ -37,28 +37,31 @@ int HIDDEN
xbps_transaction_package_replace(struct xbps_handle *xhp)
{
prop_array_t replaces, instd_reqby, unsorted;
prop_dictionary_t instd, pkg_repod, reppkgd, filesd;
prop_object_t obj;
prop_object_iterator_t iter;
prop_dictionary_t instd, reppkgd, filesd;
prop_object_t obj, obj2;
prop_object_iterator_t iter, iter2;
const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver;
char *buf;
bool instd_auto, sr;
size_t idx;
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
for (idx = 0; idx < prop_array_count(unsorted); idx++) {
pkg_repod = prop_array_get(unsorted, idx);
replaces = prop_dictionary_get(pkg_repod, "replaces");
iter = prop_array_iterator(unsorted);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
replaces = prop_dictionary_get(obj, "replaces");
if (replaces == NULL || prop_array_count(replaces) == 0)
continue;
iter = prop_array_iterator(replaces);
if (iter == NULL)
iter2 = prop_array_iterator(replaces);
if (iter2 == NULL) {
prop_object_iterator_release(iter);
return ENOMEM;
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
pattern = prop_string_cstring_nocopy(obj);
while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
pattern = prop_string_cstring_nocopy(obj2);
assert(pattern != NULL);
/*
* Find the installed package that matches the pattern
@ -74,9 +77,9 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
if (instd == NULL)
continue;
}
prop_dictionary_get_cstring_nocopy(pkg_repod,
prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkg_repod,
prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(instd,
"pkgname", &curpkgname);
@ -126,16 +129,16 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
* its requiredby and automatic-install objects, so copy
* them to the pkg's dictionary in transaction.
*/
if (xbps_match_virtual_pkg_in_dict(pkg_repod,
if (xbps_match_virtual_pkg_in_dict(obj,
pattern, true) ||
xbps_match_virtual_pkg_in_dict(instd,
pkgname, false)) {
if (instd_reqby &&
prop_array_count(instd_reqby)) {
prop_dictionary_set(pkg_repod,
prop_dictionary_set(obj,
"requiredby", instd_reqby);
}
prop_dictionary_set_bool(pkg_repod,
prop_dictionary_set_bool(obj,
"automatic-install", instd_auto);
}
/*
@ -146,14 +149,14 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
* obsolete files.
*/
sr = false;
prop_dictionary_get_bool(pkg_repod, "softreplace", &sr);
prop_dictionary_get_bool(obj, "softreplace", &sr);
if (sr) {
if (instd_reqby &&
prop_array_count(instd_reqby)) {
prop_dictionary_set(pkg_repod,
prop_dictionary_set(obj,
"requiredby", instd_reqby);
}
prop_dictionary_set_bool(pkg_repod,
prop_dictionary_set_bool(obj,
"automatic-install", instd_auto);
prop_dictionary_set_bool(instd,
"softreplace", true);
@ -168,6 +171,7 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
free(buf);
prop_object_release(filesd);
prop_object_iterator_release(iter);
prop_object_iterator_release(iter2);
return errno;
}
prop_object_release(filesd);
@ -181,8 +185,9 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
"transaction", "remove");
prop_array_add(unsorted, instd);
}
prop_object_iterator_release(iter);
prop_object_iterator_release(iter2);
}
prop_object_iterator_release(iter);
return 0;
}