From 04f899c80fcf7957bd73e4be65b6288ed5b4cbc6 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 11 Jun 2019 13:54:18 +0200 Subject: [PATCH] xbps_alternatives_unregister: fix removal of current provider. Fix logic as found by @duncaen in #101. Also set "first" when the entry is removed from the array. Fixes #102 Signed-off-by: Juan RP --- lib/package_alternatives.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/package_alternatives.c b/lib/package_alternatives.c index a91fd117..9acdc8eb 100644 --- a/lib/package_alternatives.c +++ b/lib/package_alternatives.c @@ -355,8 +355,10 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd) xbps_set_cb_state(xhp, XBPS_STATE_ALTGROUP_REMOVED, 0, NULL, "%s: unregistered '%s' alternatives group", pkgver, keyname); - if (!update) + if (!update) { xbps_remove_string_from_array(array, pkgname); + xbps_array_get_cstring_nocopy(array, 0, &first); + } if (xbps_array_count(array) == 0) { xbps_dictionary_remove(alternatives, keyname); @@ -366,9 +368,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd) if (!update && !current) continue; - xbps_array_get_cstring_nocopy(array, 0, &first); - - if (!current) { + if (current) { /* get the new alternative group package */ curpkgd = xbps_pkgdb_get_pkg(xhp, first); assert(curpkgd);