From b069eb14ae643b63cad53f4d37efcf929910db07 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 19 Oct 2015 18:01:43 +0200 Subject: [PATCH] libxbps: fixed issue #116 (vpkg does not replace pkg with update in trans). Thanks to @dominikh for the test case. --- NEWS | 4 +++ lib/transaction_package_replace.c | 14 ++++++++++ tests/xbps/libxbps/shell/replace_test.sh | 35 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/NEWS b/NEWS index 5fb1e50f..1ea3f015 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ xbps-0.48 (???): + * libxbps: fixed another issue when replacing an existing pkg with a virtual + pkg, and there's an update for the original pkg in the transaction. + Fixes #116 (https://github.com/voidlinux/xbps/issues/116). + * libxbps: the rpool functions now set errno to ENOENT when the target pkg cannot be found in registered repos. diff --git a/lib/transaction_package_replace.c b/lib/transaction_package_replace.c index 2f3502d9..d91422b6 100644 --- a/lib/transaction_package_replace.c +++ b/lib/transaction_package_replace.c @@ -88,10 +88,16 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs) xbps_dictionary_get_bool(instd, "automatic-install", &instd_auto); reppkgd = xbps_find_pkg_in_array(pkgs, curpkgname, NULL); if (reppkgd) { + const char *rpkgver; + + xbps_dictionary_get_cstring_nocopy(reppkgd, + "pkgver", &rpkgver); xbps_dictionary_get_cstring_nocopy(reppkgd, "transaction", &tract); if (strcmp(tract, "remove") == 0) continue; + if (xbps_pkgpattern_match(rpkgver, pattern) == 0) + continue; /* * Package contains replaces="pkgpattern", but the * package that should be replaced is also in the @@ -99,8 +105,16 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs) */ xbps_dictionary_set_bool(reppkgd, "automatic-install", instd_auto); + xbps_dictionary_set_cstring_nocopy(reppkgd, + "transaction", "remove"); + xbps_dictionary_set_bool(reppkgd, + "replaced", true); xbps_array_replace_dict_by_name(pkgs, reppkgd, curpkgname); + xbps_dbg_printf(xhp, + "Package `%s' in transaction will be " + "replaced by `%s', matched with `%s'\n", + curpkgver, pkgver, pattern); continue; } /* diff --git a/tests/xbps/libxbps/shell/replace_test.sh b/tests/xbps/libxbps/shell/replace_test.sh index 4eecca92..844729f0 100644 --- a/tests/xbps/libxbps/shell/replace_test.sh +++ b/tests/xbps/libxbps/shell/replace_test.sh @@ -206,11 +206,46 @@ replace_pkg_files_unmodified_body() { atf_check_equal $result 123456789 } +atf_test_case replace_pkg_with_update + +replace_pkg_with_update_head() { + atf_set "descr" "Tests for package replace: replace a pkg that needs to be updated with a vpkg (#116)" +} + +replace_pkg_with_update_body() { + mkdir some_repo root + mkdir -p pkg_A/usr/bin pkg_B/usr/bin + echo "A-1.0_1" > pkg_A/usr/bin/foo + echo "B-1.0_1" > pkg_B/usr/bin/foo + cd some_repo + xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-create -A noarch -n B-1.0_1 -s "B pkg" --replaces "A>=0" --provides="A-1.1_1" ../pkg_B + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A + atf_check_equal $? 0 + cd some_repo + xbps-create -A noarch -n A-1.1_1 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yfd A B + atf_check_equal $? 0 + result=$(xbps-query -C xbps.d -r root -l|wc -l) + atf_check_equal $result 1 + atf_check_equal $(xbps-query -C xbps.d -r root -p state B) installed +} + atf_init_test_cases() { atf_add_test_case replace_dups atf_add_test_case replace_ntimes atf_add_test_case replace_vpkg atf_add_test_case replace_pkg_files atf_add_test_case replace_pkg_files_unmodified + atf_add_test_case replace_pkg_with_update atf_add_test_case self_replace }