From 291faddf8c823503d19a69a794e1779b32b7eb4b Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 19 Apr 2019 18:52:44 +0200 Subject: [PATCH] xbps now also updates revdeps of itself if there's an update. Close https://github.com/void-linux/xbps/issues/77 Closes: #78 [via git-merge-pr] --- lib/transaction_ops.c | 31 +++++++- tests/xbps/libxbps/shell/Kyuafile | 1 + tests/xbps/libxbps/shell/Makefile | 2 +- tests/xbps/libxbps/shell/update_itself.sh | 95 +++++++++++++++++++++++ 4 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 tests/xbps/libxbps/shell/update_itself.sh diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index a2dbd2ce..f47b5bea 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -247,11 +247,36 @@ xbps_transaction_update_packages(struct xbps_handle *xhp) xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); pkgname = xbps_pkg_name(pkgver); assert(pkgname); - if (trans_find_pkg(xhp, pkgname, false, false) == 0) { - free(pkgname); + + rv = trans_find_pkg(xhp, pkgname, false, false); + free(pkgname); + + if (rv == 0) { + /* new version found, take into account its revdeps */ + xbps_array_t rdeps; + + rdeps = xbps_pkgdb_get_pkg_revdeps(xhp, "xbps"); + for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) { + const char *curpkgver; + char *curpkgn; + + xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver); + curpkgn = xbps_pkg_name(curpkgver); + assert(curpkgn); + rv = trans_find_pkg(xhp, curpkgn, false, false); + free(curpkgn); + if (rv != 0 && rv != EEXIST) + return rv; + } + + return rv; + } else if (rv == EEXIST || rv == ENOENT) { + /* no update */ + ; + } else { + /* error */ return rv; } - free(pkgname); } iter = xbps_dictionary_iterator(xhp->pkgdb); diff --git a/tests/xbps/libxbps/shell/Kyuafile b/tests/xbps/libxbps/shell/Kyuafile index 1ff87e47..731a78cc 100644 --- a/tests/xbps/libxbps/shell/Kyuafile +++ b/tests/xbps/libxbps/shell/Kyuafile @@ -20,6 +20,7 @@ atf_test_program{name="preserve_files_test"} atf_test_program{name="update_shlibs"} atf_test_program{name="update_hold"} atf_test_program{name="update_repolock"} +atf_test_program{name="update_itself"} atf_test_program{name="cyclic_deps"} atf_test_program{name="conflicts"} atf_test_program{name="downgrade_hold"} diff --git a/tests/xbps/libxbps/shell/Makefile b/tests/xbps/libxbps/shell/Makefile index 13649d0b..8a517945 100644 --- a/tests/xbps/libxbps/shell/Makefile +++ b/tests/xbps/libxbps/shell/Makefile @@ -7,7 +7,7 @@ TESTSHELL+= replace_test installmode_test obsoletefiles_test TESTSHELL+= issue31_test scripts_test incorrect_deps_test TESTSHELL+= vpkg_test install_test preserve_files_test configure_test TESTSHELL+= update_shlibs update_hold update_repolock cyclic_deps conflicts -TESTSHELL+= downgrade_hold +TESTSHELL+= update_itself downgrade_hold EXTRA_FILES = Kyuafile include $(TOPDIR)/mk/test.mk diff --git a/tests/xbps/libxbps/shell/update_itself.sh b/tests/xbps/libxbps/shell/update_itself.sh new file mode 100644 index 00000000..8deb0281 --- /dev/null +++ b/tests/xbps/libxbps/shell/update_itself.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env atf-sh + +atf_test_case update_xbps + +update_xbps_head() { + atf_set "descr" "Tests for pkg updates: xbps autoupdates itself" +} + +update_xbps_body() { + mkdir -p repo xbps + touch xbps/foo + + cd repo + xbps-create -A noarch -n xbps-1.0_1 -s "xbps pkg" ../xbps + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -r root --repository=$PWD/repo -yd xbps + atf_check_equal $? 0 + + out=$(xbps-query -r root -p pkgver xbps) + atf_check_equal "$out" "xbps-1.0_1" + + cd repo + xbps-create -A noarch -n xbps-1.1_1 -s "xbps pkg" ../xbps + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/xbps-1.1_1.noarch.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -r root --repository=$PWD/repo -yud + atf_check_equal $? 0 + + out=$(xbps-query -r root -p pkgver xbps) + atf_check_equal "$out" "xbps-1.1_1" +} + +atf_test_case update_xbps_with_revdeps + +update_xbps_with_revdeps_head() { + atf_set "descr" "Tests for pkg updates: xbps autoupdates itself with revdeps" +} + +update_xbps_with_revdeps_body() { + mkdir -p repo xbps xbps-dbg + touch xbps/foo xbps-dbg/foo + + cd repo + xbps-create -A noarch -n xbps-1.0_1 -s "xbps pkg" ../xbps + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -r root --repository=$PWD/repo -yd xbps-1.0_1 + atf_check_equal $? 0 + + cd repo + xbps-create -A noarch -n xbps-1.1_1 -s "xbps pkg" ../xbps + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + + xbps-create -A noarch -n xbps-dbg-1.0_1 -s "xbps-dbg pkg" --dependencies "xbps-1.0_1" ../xbps-dbg + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -r root --repository=$PWD/repo -yd xbps-dbg-1.0_1 + atf_check_equal $? 0 + + cd repo + xbps-create -A noarch -n xbps-dbg-1.1_1 -s "xbps-dbg pkg" --dependencies "xbps-1.1_1" ../xbps-dbg + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -r root --repository=$PWD/repo -yud + atf_check_equal $? 0 + + out=$(xbps-query -r root -p pkgver xbps) + atf_check_equal $out "xbps-1.1_1" + + out=$(xbps-query -r root -p pkgver xbps-dbg) + atf_check_equal $out "xbps-dbg-1.1_1" +} + +atf_init_test_cases() { + atf_add_test_case update_xbps + atf_add_test_case update_xbps_with_revdeps +}