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);

View File

@ -429,6 +429,35 @@ update_pkgs_body() {
atf_check_equal $rv 0
}
atf_test_case less_entries
less_entries_pkgs_head() {
atf_set "descr" "xbps-alternatives: remove symlinks not provided by the new alternative"
}
less_entries_body() {
mkdir -p repo pkg_A/usr/bin pkg_B/usr/bin
touch pkg_A/usr/bin/A1 pkg_A/usr/bin/A2 pkg_B/usr/bin/B1
cd repo
xbps-create -A noarch -n A-1.1_1 -s "A pkg" --alternatives "1:1:/usr/bin/A1 1:2:/usr/bin/A2" ../pkg_A
atf_check_equal $? 0
xbps-create -A noarch -n B-1.1_1 -s "B pkg" --alternatives "1:1:/usr/bin/B1" ../pkg_B
atf_check_equal $? 0
xbps-rindex -d -a $PWD/*.xbps
atf_check_equal $? 0
cd ..
xbps-install -r root --repository=repo -ydv A B
atf_check_equal $? 0
xbps-alternatives -r root -s B
atf_check_equal $? 0
rv=1
[ -e root/usr/bin/2 ] || rv=0
atf_check_equal $rv 0
}
atf_init_test_cases() {
atf_add_test_case register_one
atf_add_test_case register_one_dangling
@ -441,4 +470,5 @@ atf_init_test_cases() {
atf_add_test_case set_pkg
atf_add_test_case set_pkg_group
atf_add_test_case update_pkgs
atf_add_test_case less_entries
}