alternatives: do not remove symlinks if provider != target pkg.

This fixes the keep_provider_on_update test case, submitted
by @st3r4g via #219.

While checking for obsoletes make sure current provider
also matches the current target pkg.

Fixes #219
This commit is contained in:
Juan RP 2020-02-07 09:16:57 +01:00
parent 86ce5a2084
commit 94b56d7539
No known key found for this signature in database
GPG Key ID: AF19F6CB482F9368
2 changed files with 18 additions and 10 deletions

View File

@ -404,7 +404,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
/* /*
* Prune the alternatives group from the db. This will first unregister * Prune the alternatives group from the db. This will first unregister
* it for the package and if there's no other package left providing the * it for the package and if there's no other package left providing the
* same, also ditch the whole group. When this is called, it is guranteed * same, also ditch the whole group. When this is called, it is guaranteed
* that what is happening is an upgrade, because it's only invoked when * that what is happening is an upgrade, because it's only invoked when
* the repo and installed alternatives sets differ for a specific package. * the repo and installed alternatives sets differ for a specific package.
*/ */
@ -474,7 +474,7 @@ prune_altgroup(struct xbps_handle *xhp, xbps_dictionary_t repod,
static void static void
remove_obsoletes(struct xbps_handle *xhp, char *pkgname, const char *pkgver, remove_obsoletes(struct xbps_handle *xhp, char *pkgname, const char *pkgver,
xbps_dictionary_t repod) xbps_dictionary_t pkgdb_alts, xbps_dictionary_t repod)
{ {
xbps_array_t allkeys; xbps_array_t allkeys;
xbps_dictionary_t pkgd, pkgd_alts, repod_alts; xbps_dictionary_t pkgd, pkgd_alts, repod_alts;
@ -493,9 +493,9 @@ remove_obsoletes(struct xbps_handle *xhp, char *pkgname, const char *pkgver,
allkeys = xbps_dictionary_all_keys(pkgd_alts); allkeys = xbps_dictionary_all_keys(pkgd_alts);
for (unsigned int i = 0; i < xbps_array_count(allkeys); i++) { for (unsigned int i = 0; i < xbps_array_count(allkeys); i++) {
xbps_array_t array, array_repo; xbps_array_t array, array2, array_repo;
xbps_object_t keysym; xbps_object_t keysym;
const char *keyname; const char *keyname, *first;
keysym = xbps_array_get(allkeys, i); keysym = xbps_array_get(allkeys, i);
array = xbps_dictionary_get_keysym(pkgd_alts, keysym); array = xbps_dictionary_get_keysym(pkgd_alts, keysym);
@ -503,9 +503,19 @@ remove_obsoletes(struct xbps_handle *xhp, char *pkgname, const char *pkgver,
array_repo = xbps_dictionary_get(repod_alts, keyname); array_repo = xbps_dictionary_get(repod_alts, keyname);
if (!xbps_array_equals(array, array_repo)) { if (!xbps_array_equals(array, array_repo)) {
remove_symlinks(xhp, array, keyname); /*
* Check if current provider in pkgdb is this pkg.
*/
array2 = xbps_dictionary_get(pkgdb_alts, keyname);
if (array2 == NULL) {
remove_symlinks(xhp, array, keyname);
} else {
xbps_array_get_cstring_nocopy(array2, 0, &first);
if (strcmp(pkgname, first) == 0) {
remove_symlinks(xhp, array, keyname);
}
}
} }
/* /*
* There is nothing left in the alternatives group, which means * There is nothing left in the alternatives group, which means
* the package is being upgraded and is removing it; if we don't * the package is being upgraded and is removing it; if we don't
@ -551,7 +561,7 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
* Compare alternatives from pkgdb and repo and then remove obsolete * Compare alternatives from pkgdb and repo and then remove obsolete
* symlinks, also remove obsolete (empty) alternatives groups. * symlinks, also remove obsolete (empty) alternatives groups.
*/ */
remove_obsoletes(xhp, pkgname, pkgver, pkg_repod); remove_obsoletes(xhp, pkgname, pkgver, alternatives, pkg_repod);
pkg_alternatives = xbps_dictionary_get(pkg_repod, "alternatives"); pkg_alternatives = xbps_dictionary_get(pkg_repod, "alternatives");
if (!xbps_dictionary_count(pkg_alternatives)) if (!xbps_dictionary_count(pkg_alternatives))

View File

@ -809,8 +809,6 @@ keep_provider_on_update_head() {
} }
keep_provider_on_update_body() { keep_provider_on_update_body() {
atf_expect_fail "https://github.com/void-linux/xbps/issues/219"
mkdir -p tar/usr/bin/ bsdtar/usr/bin mkdir -p tar/usr/bin/ bsdtar/usr/bin
touch tar/usr/bin/gtar bsdtar/usr/bin/bsdtar touch tar/usr/bin/gtar bsdtar/usr/bin/bsdtar
mkdir repo mkdir repo
@ -837,7 +835,7 @@ keep_provider_on_update_body() {
atf_check_equal $? 0 atf_check_equal $? 0
cd .. cd ..
xbps-install -r root --repo=repo -yu xbps-install -r root --repo=repo -yud
atf_check_equal $? 0 atf_check_equal $? 0
link=$(readlink -v root/usr/bin/tar) link=$(readlink -v root/usr/bin/tar)