Do not reuse requiredby objects while updating pkgs.

--HG--
extra : convert_revision : 1bc0a25601b6ff1c4cd83de4dcd775ffdee1e9a1
This commit is contained in:
Juan RP 2009-04-06 17:00:52 +02:00
parent 4b3adf1db3
commit bb3240e4ac
4 changed files with 24 additions and 70 deletions

View File

@ -87,7 +87,7 @@ int xbps_install_binary_pkg_fini(prop_dictionary_t,
prop_dictionary_t, bool); prop_dictionary_t, bool);
int xbps_register_pkg(prop_dictionary_t, bool, bool); int xbps_register_pkg(prop_dictionary_t, bool, bool);
int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t); 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_requiredby_pkg_remove(const char *);
int xbps_find_deps_in_pkg(prop_dictionary_t, int xbps_find_deps_in_pkg(prop_dictionary_t,
prop_object_iterator_t); prop_object_iterator_t);

View File

@ -313,33 +313,29 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool update, bool automatic)
prop_dictionary_set_bool(newpkgd, "automatic-install", prop_dictionary_set_bool(newpkgd, "automatic-install",
automatic); automatic);
if (update && pkgrd && xbps_pkg_has_rundeps(pkgrd)) { /*
/* * Add the requiredby objects for dependent packages.
* If updating a package, update the requiredby */
* objects and set new version in pkg dictionary. if (pkgrd && xbps_pkg_has_rundeps(pkgrd)) {
*/ rv = xbps_requiredby_pkg_add(array, pkgrd);
rv = xbps_requiredby_pkg_add(array, pkgrd, true);
if (rv != 0) { if (rv != 0) {
prop_object_release(newpkgd); prop_object_release(newpkgd);
goto out; goto out;
} }
}
if (update) {
/*
* If updating a package, set new version in
* pkg dictionary.
*/
prop_dictionary_set_cstring_nocopy(pkgd, prop_dictionary_set_cstring_nocopy(pkgd,
"version", version); "version", version);
} else { } else {
/* /*
* If installing a package, update the requiredby * If installing a package, add new pkg
* objects and add new pkg dictionary into the * dictionary into the packages array.
* 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)) { if (!xbps_add_obj_to_array(array, newpkgd)) {
prop_object_release(newpkgd); prop_object_release(newpkgd);
rv = EINVAL; rv = EINVAL;

View File

@ -304,16 +304,16 @@ xbps_remove_binary_pkg(const char *pkgname, bool update)
free(buf); free(buf);
/* /*
* Update the required_by array of all required dependencies * Update the requiredby array of all required dependencies.
* and unregister package if this is really a removal and
* not an update.
*/ */
rv = xbps_requiredby_pkg_remove(pkgname);
if (rv != 0)
return rv;
if (update == false) { 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); rv = xbps_unregister_pkg(pkgname);
if (rv != 0) if (rv != 0)

View File

@ -119,44 +119,6 @@ remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done)
return 0; 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 int
xbps_requiredby_pkg_remove(const char *pkgname) xbps_requiredby_pkg_remove(const char *pkgname)
{ {
@ -191,7 +153,7 @@ xbps_requiredby_pkg_remove(const char *pkgname)
} }
int 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_array_t rdeps;
prop_object_t obj, obj2; 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", prop_dictionary_get_cstring_nocopy(obj2, "pkgname",
&reqname); &reqname);
if (strcmp(rdepname, reqname) == 0) { if (strcmp(rdepname, reqname) == 0) {
if (update) rv = add_pkg_into_reqby(obj2, fpkgn);
rv = update_pkg_from_reqby(obj2,
pkgname, fpkgn);
else
rv = add_pkg_into_reqby(obj2, fpkgn);
if (rv != 0) { if (rv != 0) {
free(rdepname); free(rdepname);
prop_object_iterator_release(iter2); prop_object_iterator_release(iter2);