From 825f1f30f92c0540bca809220692c6c4441d3ce7 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Tue, 30 May 2023 21:16:28 +0200 Subject: [PATCH] lib: with XBPS_FLAG_INSTALL_AUTO only mark new installs as automatic Closes: https://github.com/void-linux/xbps/issues/556 --- lib/package_register.c | 12 -- lib/transaction_ops.c | 9 +- tests/xbps/libxbps/shell/installmode_test.sh | 115 +++++++++++++++++++ 3 files changed, 123 insertions(+), 13 deletions(-) diff --git a/lib/package_register.c b/lib/package_register.c index 805856e8..5ea2f6f9 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -41,7 +41,6 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd) const char *pkgver, *pkgname; char sha256[XBPS_SHA256_SIZE], outstr[64], *buf; int rv = 0; - bool autoinst = false; assert(xbps_object_type(pkgrd) == XBPS_TYPE_DICTIONARY); @@ -53,17 +52,6 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd) xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname); - if (xhp->flags & XBPS_FLAG_INSTALL_AUTO) - autoinst = true; - /* - * Set automatic-install to true, iff it was explicitly set; otherwise - * preserve its value. - */ - if (autoinst && !xbps_dictionary_set_bool(pkgd, "automatic-install", true)) { - xbps_dbg_printf("%s: invalid autoinst for %s\n", __func__, pkgver); - rv = EINVAL; - goto out; - } if (xhp->flags & XBPS_FLAG_INSTALL_REPRO) { /* * Reproducible mode. Some objects must not be recorded: diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index 1f123901..d4fef601 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -62,6 +62,7 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force) xbps_trans_type_t ttype; const char *repoloc, *repopkgver, *instpkgver, *pkgname; char buf[XBPS_NAME_SIZE] = {0}; + bool autoinst = false; int rv = 0; assert(pkg != NULL); @@ -208,7 +209,13 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force) return EINVAL; } - if (!xbps_transaction_store(xhp, pkgs, pkg_repod, false)) { + /* + * Set automatic-install to true if it was requested and this is a new install. + */ + if (ttype == XBPS_TRANS_INSTALL) + autoinst = xhp->flags & XBPS_FLAG_INSTALL_AUTO; + + if (!xbps_transaction_store(xhp, pkgs, pkg_repod, autoinst)) { return EINVAL; } diff --git a/tests/xbps/libxbps/shell/installmode_test.sh b/tests/xbps/libxbps/shell/installmode_test.sh index a9e767a3..7363609f 100644 --- a/tests/xbps/libxbps/shell/installmode_test.sh +++ b/tests/xbps/libxbps/shell/installmode_test.sh @@ -229,6 +229,118 @@ instmode_dependency_configure_body() { atf_check_equal $out "" } +atf_test_case instmode_auto_dependency_update + +instmode_auto_dependency_update_head() { + atf_set "descr" "Installation mode: auto preserve on install with dependency update" +} + +instmode_auto_dependency_update_body() { + mkdir some_repo + mkdir -p pkg_A/usr/bin pkg_B/usr/bin + touch -f pkg_A/usr/bin/foo pkg_B/usr/bin/blah + + cd some_repo + xbps-create -A noarch -n A-1.0_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + + cd .. + xbps-install -r root -C null.conf --repository=$PWD/some_repo -yd A-1.0_1 + atf_check_equal $? 0 + + cd some_repo + xbps-create -A noarch -n A-1.1_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + xbps-create -A noarch -n B-1.1_1 -s "foo pkg" -D "A>=1.1_1" ../pkg_B + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + + cd .. + xbps-install -r root -C null.conf --repository=$PWD/some_repo -Ayd B + atf_check_equal $? 0 + out="$(xbps-query -r root --property=automatic-install A)" + atf_check_equal $out "" + out="$(xbps-query -r root --property=automatic-install B)" + atf_check_equal $out "yes" +} + +atf_test_case instmode_auto_dependency_update_automatic + +instmode_auto_dependency_update_automatic_head() { + atf_set "descr" "Installation mode: auto preserve on install with dependency update marked automatic" +} + +instmode_auto_dependency_update_automatic_body() { + mkdir some_repo + mkdir -p pkg_A/usr/bin pkg_B/usr/bin + touch -f pkg_A/usr/bin/foo pkg_B/usr/bin/blah + + cd some_repo + xbps-create -A noarch -n A-1.0_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + + cd .. + xbps-install -r root -C null.conf --repository=$PWD/some_repo -Ayd A-1.0_1 + atf_check_equal $? 0 + + cd some_repo + xbps-create -A noarch -n A-1.1_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + xbps-create -A noarch -n B-1.1_1 -s "foo pkg" -D "A>=1.1_1" ../pkg_B + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + + cd .. + xbps-install -r root -C null.conf --repository=$PWD/some_repo -Ayd B + atf_check_equal $? 0 + out="$(xbps-query -r root --property=automatic-install A)" + atf_check_equal $out "yes" + out="$(xbps-query -r root --property=automatic-install B)" + atf_check_equal $out "yes" +} + +atf_test_case instmode_auto_dependency_configure + +instmode_auto_dependency_configure_head() { + atf_set "descr" "Installation mode: auto preserve on install with dependency configure" +} + +instmode_auto_dependency_configure_body() { + mkdir some_repo + mkdir -p pkg_A/usr/bin pkg_B/usr/bin + touch -f pkg_A/usr/bin/foo pkg_B/usr/bin/blah + + cd some_repo + xbps-create -A noarch -n A-1.0_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + + cd .. + xbps-install -r root -C null.conf --repository=$PWD/some_repo -Uyd A-1.0_1 + atf_check_equal $? 0 + + cd some_repo + xbps-create -A noarch -n B-1.1_1 -s "foo pkg" -D "A>=0" ../pkg_B + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + + cd .. + xbps-install -r root -C null.conf --repository=$PWD/some_repo -Ayd B + atf_check_equal $? 0 + out="$(xbps-query -r root --property=automatic-install A)" + atf_check_equal $out "" + out="$(xbps-query -r root --property=automatic-install B)" + atf_check_equal $out "yes" +} + atf_init_test_cases() { atf_add_test_case instmode atf_add_test_case instmode_auto @@ -237,4 +349,7 @@ atf_init_test_cases() { atf_add_test_case instmode_dependency_update atf_add_test_case instmode_dependency_update_automatic atf_add_test_case instmode_dependency_configure + atf_add_test_case instmode_auto_dependency_update + atf_add_test_case instmode_auto_dependency_update_automatic + atf_add_test_case instmode_auto_dependency_configure }