lib/package_alternatives.c: remove previous symlinks

This commit is contained in:
Duncaen
2016-09-04 17:20:44 +02:00
parent 2aa538bf35
commit dd7a0d073b
2 changed files with 46 additions and 2 deletions

View File

@@ -249,8 +249,8 @@ xbps_alternatives_set(struct xbps_handle *xhp, const char *pkgname,
const char *group)
{
xbps_array_t allkeys;
xbps_dictionary_t alternatives, pkg_alternatives, pkgd;
const char *pkgver;
xbps_dictionary_t alternatives, pkg_alternatives, pkgd, prevpkgd, prevpkg_alts;
const char *pkgver, *prevpkgname;
int rv = 0;
assert(xhp);
@@ -289,6 +289,20 @@ xbps_alternatives_set(struct xbps_handle *xhp, const char *pkgname,
if (array == NULL)
continue;
/* remove symlinks from previous alternative */
xbps_array_get_cstring_nocopy(array, 0, &prevpkgname);
if (prevpkgname && strcmp(pkgname, prevpkgname) != 0) {
if ((prevpkgd = xbps_pkgdb_get_pkg(xhp, prevpkgname)) &&
(prevpkg_alts = xbps_dictionary_get(prevpkgd, "alternatives")) &&
xbps_dictionary_count(prevpkg_alts)) {
rv = remove_symlinks(xhp,
xbps_dictionary_get(prevpkg_alts, keyname),
keyname);
if (rv != 0)
break;
}
}
/* put this alternative group at the head */
xbps_remove_string_from_array(array, pkgname);
kstr = xbps_string_create_cstring(pkgname);