diff --git a/include/xbps_api.h b/include/xbps_api.h index 198f5f92..9b23d81c 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,7 +56,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.5" -#define XBPS_API_VERSION "20120604" +#define XBPS_API_VERSION "20120604-1" #define XBPS_VERSION "0.16" /** diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index 5c5a7167..885352ed 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -134,16 +134,7 @@ int HIDDEN xbps_requiredby_pkg_remove(const char *); prop_dictionary_t HIDDEN xbps_find_virtualpkg_conf_in_array_by_name(prop_array_t, const char *); prop_dictionary_t HIDDEN - xbps_find_virtualpkg_conf_in_dict_by_name(prop_dictionary_t, - const char *, - const char *); -prop_dictionary_t HIDDEN - xbps_find_virtualpkg_conf_in_array_by_pattern(prop_array_t, - const char *); -prop_dictionary_t HIDDEN - xbps_find_virtualpkg_conf_in_dict_by_pattern(prop_dictionary_t, - const char *, - const char *); + xbps_find_virtualpkg_conf_in_array_by_pattern(prop_array_t, const char *); /** * @private diff --git a/lib/plist_find.c b/lib/plist_find.c index 517f19f1..e1ce677b 100644 --- a/lib/plist_find.c +++ b/lib/plist_find.c @@ -61,9 +61,10 @@ find_pkg_in_array(prop_array_t array, while ((obj = prop_object_iterator_next(iter))) { chkarch = prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch); + if (chkarch && !xbps_pkg_arch_match(arch, targetarch)) + continue; + if (virtual) { - if (chkarch && !xbps_pkg_arch_match(arch, targetarch)) - continue; /* * Check if package pattern matches * any virtual package version in dictionary. @@ -72,8 +73,6 @@ find_pkg_in_array(prop_array_t array, break; } else if (bypattern) { - if (chkarch && !xbps_pkg_arch_match(arch, targetarch)) - continue; /* * Check if package pattern matches the * pkgver string object in dictionary. @@ -84,8 +83,6 @@ find_pkg_in_array(prop_array_t array, if (xbps_pkgpattern_match(pkgver, str)) break; } else { - if (chkarch && !xbps_pkg_arch_match(arch, targetarch)) - continue; if (!prop_dictionary_get_cstring_nocopy(obj, "pkgname", &dpkgn)) continue; @@ -239,25 +236,6 @@ xbps_find_virtualpkg_conf_in_array_by_pattern(prop_array_t array, const char *p) return find_virtualpkg_user_in_array(array, p, true); } -static prop_dictionary_t -find_virtualpkg_user_in_dict(prop_dictionary_t d, - const char *key, - const char *str, - bool bypattern) -{ - prop_array_t array; - - assert(prop_object_type(d) == PROP_TYPE_DICTIONARY); - assert(str != NULL); - assert(key != NULL); - - array = prop_dictionary_get(d, key); - if (prop_object_type(array) != PROP_TYPE_ARRAY) - return NULL; - - return find_virtualpkg_user_in_array(array, str, bypattern); -} - static prop_dictionary_t find_pkg_in_dict(prop_dictionary_t d, const char *key, @@ -328,22 +306,6 @@ xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d, return find_pkg_in_dict(d, key, pattern, true, true); } -prop_dictionary_t HIDDEN -xbps_find_virtualpkg_conf_in_dict_by_name(prop_dictionary_t d, - const char *key, - const char *name) -{ - return find_virtualpkg_user_in_dict(d, key, name, false); -} - -prop_dictionary_t HIDDEN -xbps_find_virtualpkg_conf_in_dict_by_pattern(prop_dictionary_t d, - const char *key, - const char *pattern) -{ - return find_virtualpkg_user_in_dict(d, key, pattern, true); -} - static prop_dictionary_t find_pkgd_installed(const char *str, bool bypattern, bool virtual) { diff --git a/lib/repository_finddeps.c b/lib/repository_finddeps.c index 4f369104..35bfc47d 100644 --- a/lib/repository_finddeps.c +++ b/lib/repository_finddeps.c @@ -31,25 +31,13 @@ #include "xbps_api_impl.h" static int -store_dependency(prop_dictionary_t transd, +store_dependency(prop_array_t transd_unsorted, 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 array; - const char *pkgname, *pkgver, *repoloc; - size_t x; - int rv = 0; - - assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); - assert(prop_object_type(repo_pkgd) == PROP_TYPE_DICTIONARY); - /* - * Get some info about dependencies and current repository. - */ - prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgname", &pkgname); - prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver); - prop_dictionary_get_cstring_nocopy(repo_pkgd, "repository", &repoloc); + int rv; /* * Overwrite package state in dictionary with same state than the * package currently uses, otherwise not-installed. @@ -60,27 +48,28 @@ store_dependency(prop_dictionary_t transd, * Add required objects into package dep's dictionary. */ if (!prop_dictionary_set_bool(repo_pkgd, "automatic-install", true)) - return errno; - + return EINVAL; /* * Add the dictionary into the array. */ - array = prop_dictionary_get(transd, "unsorted_deps"); - if (array == NULL) - return errno; - - if (!prop_array_add(array, repo_pkgd)) + if (!prop_array_add(transd_unsorted, repo_pkgd)) return EINVAL; if (xhp->flags & XBPS_FLAG_DEBUG) { + size_t x; + const char *repo, *pkgver; + + prop_dictionary_get_cstring_nocopy(repo_pkgd, + "repository", &repo); + prop_dictionary_get_cstring_nocopy(repo_pkgd, + "pkgver", &pkgver); xbps_dbg_printf(" "); for (x = 0; x < *depth; x++) xbps_dbg_printf_append(" "); xbps_dbg_printf_append("%s: added into " - "the transaction (%s).\n", pkgver, repoloc); + "the transaction (%s).\n", pkgver, repo); } - return 0; } @@ -182,32 +171,22 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ prop_dictionary_t curpkgd, tmpd; prop_array_t curpkgrdeps, unsorted; prop_object_t obj; - prop_object_iterator_t iter; pkg_state_t state; - size_t x; + size_t i, x; const char *reqpkg, *pkgver_q, *reason = NULL; char *pkgname; int rv = 0; - assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); - assert(prop_object_type(trans_mdeps) == PROP_TYPE_ARRAY); - assert(prop_object_type(pkg_rdeps_array) == PROP_TYPE_ARRAY); - if (*depth >= MAX_DEPTH) return ELOOP; - iter = prop_array_iterator(pkg_rdeps_array); - if (iter == NULL) - return ENOMEM; - /* * Iterate over the list of required run dependencies for * current package. */ - while ((obj = prop_object_iterator_next(iter)) != NULL) { - curpkgd = NULL; - reqpkg = prop_string_cstring_nocopy(obj); - if (reqpkg == NULL) { + for (i = 0; i < prop_array_count(pkg_rdeps_array); i++) { + obj = prop_array_get(pkg_rdeps_array, i); + if ((reqpkg = prop_string_cstring_nocopy(obj)) == NULL) { rv = EINVAL; break; } @@ -222,8 +201,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ * Pass 1: check if required dependency is already installed * and its version is fully matched. */ - pkgname = xbps_pkgpattern_name(reqpkg); - if (pkgname == NULL) { + if ((pkgname = xbps_pkgpattern_name(reqpkg)) == NULL) { rv = EINVAL; xbps_dbg_printf("failed to get " "pkgname from `%s'!", reqpkg); @@ -248,8 +226,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ */ tmpd = xbps_find_virtualpkg_dict_installed(pkgname, false); } + free(pkgname); if (tmpd == NULL) { - free(pkgname); if (errno && errno != ENOENT) { /* error */ rv = errno; @@ -273,11 +251,9 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ /* Check its state */ rv = xbps_pkg_state_dictionary(tmpd, &state); if (rv != 0) { - free(pkgname); prop_object_release(tmpd); break; } - free(pkgname); if (xbps_match_virtual_pkg_in_dict(tmpd,reqpkg,true)) { /* * Check if required dependency is a virtual @@ -330,13 +306,12 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ } } /* - * Pass 2: - * check if required dependency was already added - * in the transaction. + * Pass 2: check if required dependency has been already + * added in the transaction dictionary. */ unsorted = prop_dictionary_get(transd, "unsorted_deps"); - if (((curpkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(unsorted, reqpkg)) == NULL) && - ((curpkgd = xbps_find_pkg_in_array_by_pattern(unsorted, reqpkg, NULL)) == NULL) && + 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_in_array_by_pattern(unsorted, reqpkg)) == NULL)) { /* error matching required pkgdep */ if (errno && errno != ENOENT) { @@ -384,12 +359,11 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ continue; } } - prop_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason); - prop_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q); /* * Package is on repo, add it into the transaction dictionary. */ - rv = store_dependency(transd, curpkgd, state, depth); + prop_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason); + rv = store_dependency(unsorted, curpkgd, state, depth); if (rv != 0) { xbps_dbg_printf("store_dependency failed for " "`%s': %s\n", reqpkg, strerror(rv)); @@ -425,7 +399,6 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ break; } } - prop_object_iterator_release(iter); (*depth)--; return rv; @@ -438,10 +411,6 @@ xbps_repository_find_pkg_deps(struct xbps_handle *xhp, prop_array_t mdeps, pkg_rdeps; const char *pkgver; size_t depth = 0; - int rv = 0; - - assert(prop_object_type(xhp->transd) == PROP_TYPE_DICTIONARY); - assert(prop_object_type(repo_pkgd) == PROP_TYPE_DICTIONARY); pkg_rdeps = prop_dictionary_get(repo_pkgd, "run_depends"); if (prop_object_type(pkg_rdeps) != PROP_TYPE_ARRAY) @@ -454,11 +423,5 @@ xbps_repository_find_pkg_deps(struct xbps_handle *xhp, * This will find direct and indirect deps, if any of them is not * there it will be added into the missing_deps array. */ - if ((rv = find_repo_deps(xhp->transd, mdeps, pkg_rdeps, - pkgver, &depth)) != 0) { - xbps_dbg_printf("Error '%s' while checking rundeps!\n", - strerror(rv)); - } - - return rv; + return find_repo_deps(xhp->transd, mdeps, pkg_rdeps, pkgver, &depth); } diff --git a/lib/repository_pool_find.c b/lib/repository_pool_find.c index d9c79b5a..fd4c51b5 100644 --- a/lib/repository_pool_find.c +++ b/lib/repository_pool_find.c @@ -49,8 +49,6 @@ repo_find_virtualpkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done) { struct repo_pool_fpkg *rpf = arg; - assert(rpi != NULL); - if (rpf->bypattern) { rpf->pkgd = xbps_find_virtualpkg_in_array_by_pattern(rpi->repo, @@ -74,8 +72,6 @@ repo_find_virtualpkg_conf_cb(struct xbps_rpool_index *rpi, void *arg, bool *done { struct repo_pool_fpkg *rpf = arg; - assert(rpi != NULL); - if (rpf->bypattern) { rpf->pkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(rpi->repo, @@ -99,8 +95,6 @@ repo_find_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done) { struct repo_pool_fpkg *rpf = arg; - assert(rpi != NULL); - if (rpf->exact) { /* exact match by pkgver */ rpf->pkgd = xbps_find_pkg_in_array_by_pkgver(rpi->repo, @@ -134,8 +128,6 @@ repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done) const char *repopkgver; prop_dictionary_t pkgd; - assert(rpi != NULL); - (void)done; if (rpf->bypattern) { @@ -185,129 +177,92 @@ typedef enum { REAL_PKG } pkg_repo_type_t; -static struct repo_pool_fpkg * +static prop_dictionary_t repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type) { - struct repo_pool_fpkg *rpf; + struct repo_pool_fpkg rpf; int rv = 0; - assert(pkg != NULL); - - rpf = malloc(sizeof(*rpf)); - if (rpf == NULL) - return NULL; - - rpf->pattern = pkg; - rpf->bypattern = bypattern; - rpf->exact = false; - rpf->pkgd = NULL; - rpf->bestpkgver = NULL; + rpf.pattern = pkg; + rpf.bypattern = bypattern; + rpf.exact = false; + rpf.pkgd = NULL; + rpf.bestpkgver = NULL; switch (type) { case EXACT_PKG: /* * Find exact pkg version. */ - rpf->exact = true; - rv = xbps_rpool_foreach(repo_find_pkg_cb, rpf); + rpf.exact = true; + rv = xbps_rpool_foreach(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(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(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(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(repo_find_pkg_cb, &rpf); break; } - if (rv != 0) + if (rv != 0) { errno = rv; + return NULL; + } - return rpf; + return prop_dictionary_copy(rpf.pkgd); } prop_dictionary_t xbps_rpool_find_virtualpkg(const char *pkg, bool bypattern) { - struct repo_pool_fpkg *rpf; - prop_dictionary_t pkgd = NULL; - assert(pkg != NULL); - rpf = repo_find_pkg(pkg, bypattern, VIRTUAL_PKG); - if (prop_object_type(rpf->pkgd) == PROP_TYPE_DICTIONARY) - pkgd = prop_dictionary_copy(rpf->pkgd); - free(rpf); - - return pkgd; + return repo_find_pkg(pkg, bypattern, VIRTUAL_PKG); } prop_dictionary_t xbps_rpool_find_virtualpkg_conf(const char *pkg, bool bypattern) { - struct repo_pool_fpkg *rpf; - prop_dictionary_t pkgd = NULL; - assert(pkg != NULL); - rpf = repo_find_pkg(pkg, bypattern, VIRTUAL_CONF_PKG); - if (prop_object_type(rpf->pkgd) == PROP_TYPE_DICTIONARY) - pkgd = prop_dictionary_copy(rpf->pkgd); - free(rpf); - - return pkgd; + return repo_find_pkg(pkg, bypattern, VIRTUAL_CONF_PKG); } prop_dictionary_t xbps_rpool_find_pkg(const char *pkg, bool bypattern, bool best) { - struct repo_pool_fpkg *rpf; - prop_dictionary_t pkgd = NULL; - assert(pkg != NULL); if (best) - rpf = repo_find_pkg(pkg, bypattern, BEST_PKG); - else - rpf = repo_find_pkg(pkg, bypattern, REAL_PKG); + return repo_find_pkg(pkg, bypattern, BEST_PKG); - if (prop_object_type(rpf->pkgd) == PROP_TYPE_DICTIONARY) - pkgd = prop_dictionary_copy(rpf->pkgd); - free(rpf); - - return pkgd; + return repo_find_pkg(pkg, bypattern, REAL_PKG); } prop_dictionary_t xbps_rpool_find_pkg_exact(const char *pkgver) { - struct repo_pool_fpkg *rpf; - prop_dictionary_t pkgd = NULL; - assert(pkgver != NULL); - rpf = repo_find_pkg(pkgver, false, EXACT_PKG); - if (prop_object_type(rpf->pkgd) == PROP_TYPE_DICTIONARY) - pkgd = prop_dictionary_copy(rpf->pkgd); - free(rpf); - - return pkgd; + return repo_find_pkg(pkgver, false, EXACT_PKG); } prop_dictionary_t diff --git a/lib/transaction_dictionary.c b/lib/transaction_dictionary.c index 779d76cd..61cd128e 100644 --- a/lib/transaction_dictionary.c +++ b/lib/transaction_dictionary.c @@ -79,20 +79,16 @@ compute_transaction_stats(prop_dictionary_t transd) prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract); prop_dictionary_get_cstring_nocopy(obj, "repository", &repo); - if (strcmp(tract, "install") == 0) - inst_pkgcnt++; - else if (strcmp(tract, "update") == 0) - up_pkgcnt++; - else if (strcmp(tract, "configure") == 0) + if (strcmp(tract, "configure") == 0) { cf_pkgcnt++; - else if (strcmp(tract, "remove") == 0) - rm_pkgcnt++; - - /* - * Only process pkgs to be installed or updated. - */ - if (strcmp(tract, "configure") == 0) continue; + } else if (strcmp(tract, "install") == 0) { + inst_pkgcnt++; + } else if (strcmp(tract, "update") == 0) { + up_pkgcnt++; + } else if (strcmp(tract, "remove") == 0) { + rm_pkgcnt++; + } tsize = 0; /* @@ -199,24 +195,20 @@ xbps_transaction_init(struct xbps_handle *xhp) if (xhp->transd != NULL) return 0; - xhp->transd = prop_dictionary_create(); - if (xhp->transd == NULL) + if ((xhp->transd = prop_dictionary_create()) == NULL) return ENOMEM; - unsorted = prop_array_create(); - if (unsorted == NULL) { + if ((unsorted = prop_array_create()) == NULL) { prop_object_release(xhp->transd); xhp->transd = NULL; return ENOMEM; } - if (!xbps_add_obj_to_dict(xhp->transd, unsorted, "unsorted_deps")) { prop_object_release(xhp->transd); xhp->transd = NULL; return EINVAL; } - mdeps = prop_array_create(); - if (mdeps == NULL) { + if ((mdeps = prop_array_create()) == NULL) { prop_object_release(xhp->transd); xhp->transd = NULL; return ENOMEM; diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index c0f6f5dd..684b4930 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -110,7 +110,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact, prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &repover); prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc); - if (best && (action == TRANS_UPDATE)) { + if (action == TRANS_UPDATE) { /* * Compare installed version vs best pkg available in repos. */ @@ -130,13 +130,11 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact, */ if ((rv = xbps_transaction_init(xhp)) != 0) goto out; - /* * Prepare required package dependencies and add them into the * "unsorted" array in transaction dictionary. */ - if ((xbps_pkg_has_rundeps(pkg_repod)) && - ((rv = xbps_repository_find_pkg_deps(xhp, pkg_repod)) != 0)) + if ((rv = xbps_repository_find_pkg_deps(xhp, pkg_repod)) != 0) goto out; /* * Set package state in dictionary with same state than the