From bb3240e4ac0294a3c66eec7cdfc6756c1174f6b7 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 6 Apr 2009 17:00:52 +0200 Subject: [PATCH] Do not reuse requiredby objects while updating pkgs. --HG-- extra : convert_revision : 1bc0a25601b6ff1c4cd83de4dcd775ffdee1e9a1 --- include/xbps_api.h | 2 +- lib/install.c | 32 ++++++++++++++------------------ lib/remove.c | 14 +++++++------- lib/requiredby.c | 46 ++-------------------------------------------- 4 files changed, 24 insertions(+), 70 deletions(-) diff --git a/include/xbps_api.h b/include/xbps_api.h index 7d747c4ac9d..295136f8a3f 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -87,7 +87,7 @@ int xbps_install_binary_pkg_fini(prop_dictionary_t, prop_dictionary_t, bool); int xbps_register_pkg(prop_dictionary_t, bool, bool); int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t); -int xbps_requiredby_pkg_add(prop_array_t, prop_dictionary_t, bool); +int xbps_requiredby_pkg_add(prop_array_t, prop_dictionary_t); int xbps_requiredby_pkg_remove(const char *); int xbps_find_deps_in_pkg(prop_dictionary_t, prop_object_iterator_t); diff --git a/lib/install.c b/lib/install.c index 4db78470e1f..46989fa80eb 100644 --- a/lib/install.c +++ b/lib/install.c @@ -313,33 +313,29 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool update, bool automatic) prop_dictionary_set_bool(newpkgd, "automatic-install", automatic); - if (update && pkgrd && xbps_pkg_has_rundeps(pkgrd)) { - /* - * If updating a package, update the requiredby - * objects and set new version in pkg dictionary. - */ - rv = xbps_requiredby_pkg_add(array, pkgrd, true); + /* + * Add the requiredby objects for dependent packages. + */ + if (pkgrd && xbps_pkg_has_rundeps(pkgrd)) { + rv = xbps_requiredby_pkg_add(array, pkgrd); if (rv != 0) { prop_object_release(newpkgd); goto out; } + } + + if (update) { + /* + * If updating a package, set new version in + * pkg dictionary. + */ prop_dictionary_set_cstring_nocopy(pkgd, "version", version); - } else { /* - * If installing a package, update the requiredby - * objects and add new pkg dictionary into the - * packages array. + * If installing a package, add new pkg + * dictionary into the packages array. */ - if (pkgrd && xbps_pkg_has_rundeps(pkgrd)) { - rv = xbps_requiredby_pkg_add(array, pkgrd, - false); - if (rv != 0) { - prop_object_release(newpkgd); - goto out; - } - } if (!xbps_add_obj_to_array(array, newpkgd)) { prop_object_release(newpkgd); rv = EINVAL; diff --git a/lib/remove.c b/lib/remove.c index 797d6ab4c7c..33109c1b105 100644 --- a/lib/remove.c +++ b/lib/remove.c @@ -304,16 +304,16 @@ xbps_remove_binary_pkg(const char *pkgname, bool update) free(buf); /* - * Update the required_by array of all required dependencies - * and unregister package if this is really a removal and - * not an update. + * Update the requiredby array of all required dependencies. */ + rv = xbps_requiredby_pkg_remove(pkgname); + if (rv != 0) + return rv; + if (update == false) { - rv = xbps_requiredby_pkg_remove(pkgname); - if (rv != 0) - return rv; /* - * Unregister pkg from database. + * Unregister pkg from database only if it's a removal + * and not an update. */ rv = xbps_unregister_pkg(pkgname); if (rv != 0) diff --git a/lib/requiredby.c b/lib/requiredby.c index 54189aab39e..19fd87ea219 100644 --- a/lib/requiredby.c +++ b/lib/requiredby.c @@ -119,44 +119,6 @@ remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done) return 0; } -static int -update_pkg_from_reqby(prop_dictionary_t pkgd, const char *reqname, - const char *reqpkg) -{ - prop_array_t reqby; - prop_object_iterator_t iter; - prop_object_t obj; - size_t idx = 0; - char *pkgname; - bool found = false; - - reqby = prop_dictionary_get(pkgd, "requiredby"); - if (reqby == NULL || prop_array_count(reqby) == 0) - return EINVAL; - - iter = prop_array_iterator(reqby); - if (iter == NULL) - return ENOMEM; - - while ((obj = prop_object_iterator_next(iter)) != NULL) { - pkgname = xbps_get_pkg_name(prop_string_cstring_nocopy(obj)); - if (strcmp(reqname, pkgname) == 0) { - found = true; - break; - } - idx++; - } - prop_object_iterator_release(iter); - if (found == false) - return ENOENT; - - obj = prop_string_create_cstring(reqpkg); - if (!prop_array_set(reqby, idx, obj)) - return EINVAL; - - return 0; -} - int xbps_requiredby_pkg_remove(const char *pkgname) { @@ -191,7 +153,7 @@ xbps_requiredby_pkg_remove(const char *pkgname) } int -xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg, bool update) +xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg) { prop_array_t rdeps; prop_object_t obj, obj2; @@ -235,11 +197,7 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg, bool update) prop_dictionary_get_cstring_nocopy(obj2, "pkgname", &reqname); if (strcmp(rdepname, reqname) == 0) { - if (update) - rv = update_pkg_from_reqby(obj2, - pkgname, fpkgn); - else - rv = add_pkg_into_reqby(obj2, fpkgn); + rv = add_pkg_into_reqby(obj2, fpkgn); if (rv != 0) { free(rdepname); prop_object_iterator_release(iter2);