From 98a37239023bd09e975388aed32f0a7c4f8b4265 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 15 Jan 2014 16:17:41 +0100 Subject: [PATCH] Respect installation mode also on reinstall (and downgrade). --- NEWS | 3 + lib/transaction_ops.c | 13 +++- tests/xbps/libxbps/common/Kyuafile | 1 + tests/xbps/libxbps/shell/Makefile | 2 +- tests/xbps/libxbps/shell/installmode_test.sh | 67 ++++++++++++++++++++ 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 tests/xbps/libxbps/shell/installmode_test.sh diff --git a/NEWS b/NEWS index c8d1586a..0858c074 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ xbps-0.30 (??): + * When reinstalling a package (or downgrading) make sure to also respect + its installation mode (automatic or manual). + * Fixed a bug where in some cases valid symlinks in a package were not removed (just dangling symlinks were removed). diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index 6e50f9d7..44829da4 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -70,6 +70,10 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, int action) assert(pkg != NULL); + /* + * Find out if pkg is installed first. + */ + pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkg); /* * Find out if the pkg has been found in repository pool. */ @@ -81,7 +85,7 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, int action) return ENOENT; } } else { - if ((pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkg)) == NULL) + if (pkg_pkgdb == NULL) return ENODEV; reason = "update"; @@ -105,7 +109,12 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, int action) repopkgver, instpkgver, repoloc); return EEXIST; } - /* respect current install mode from pkgdb */ + } + if (pkg_pkgdb) { + /* + * If pkg is already installed, respect its automatic-install + * property. + */ xbps_dictionary_get_bool(pkg_pkgdb, "automatic-install", &autoinst); xbps_dictionary_set_bool(pkg_repod, "automatic-install", diff --git a/tests/xbps/libxbps/common/Kyuafile b/tests/xbps/libxbps/common/Kyuafile index faf710a9..c484cefc 100644 --- a/tests/xbps/libxbps/common/Kyuafile +++ b/tests/xbps/libxbps/common/Kyuafile @@ -14,6 +14,7 @@ atf_test_program{name="issue20_test"} atf_test_program{name="conf_files_test"} atf_test_program{name="remove_test"} atf_test_program{name="replace_test"} +atf_test_program{name="installmode_test"} include('find_pkg_orphans/Kyuafile') include('pkgdb/Kyuafile') diff --git a/tests/xbps/libxbps/shell/Makefile b/tests/xbps/libxbps/shell/Makefile index 21dbe883..fe683514 100644 --- a/tests/xbps/libxbps/shell/Makefile +++ b/tests/xbps/libxbps/shell/Makefile @@ -2,7 +2,7 @@ TOPDIR = ../../../.. -include $(TOPDIR)/config.mk TESTSHELL = conf_files_test issue6_test issue18_test issue20_test remove_test -TESTSHELL+= replace_test +TESTSHELL+= replace_test installmode_test include ../Makefile.inc include $(TOPDIR)/mk/test.mk diff --git a/tests/xbps/libxbps/shell/installmode_test.sh b/tests/xbps/libxbps/shell/installmode_test.sh new file mode 100644 index 00000000..b253c2d9 --- /dev/null +++ b/tests/xbps/libxbps/shell/installmode_test.sh @@ -0,0 +1,67 @@ +#! /usr/bin/env atf-sh + +# 1- preserve installation mode on updates +atf_test_case instmode_update + +instmode_update_head() { + atf_set "descr" "Installation mode: preserve on update" +} + +instmode_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 -a *.xbps + atf_check_equal $? 0 + + cd .. + xbps-install -r root -C null.conf --repository=$PWD/some_repo -A -y A-1.0_1 + atf_check_equal $? 0 + + cd some_repo + xbps-create -A noarch -n A-1.1_1 -s "foo pkg" ../pkg_B + atf_check_equal $? 0 + xbps-rindex -a *.xbps + atf_check_equal $? 0 + + cd .. + xbps-install -r root -C null.conf --repository=$PWD/some_repo -yu + atf_check_equal $? 0 + out=$(xbps-query -r root --property=automatic-install A) + atf_check_equal $out yes +} + +# 2- preserve installation mode on reinstall +atf_test_case instmode_reinstall + +instmode_reinstall_head() { + atf_set "descr" "Installation mode: preserve on reinstall" +} + +instmode_reinstall_body() { + mkdir some_repo + mkdir -p pkg_A/usr/bin + touch -f pkg_A/usr/bin/foo + + cd some_repo + xbps-create -A noarch -n A-1.0_1 -s "foo pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -a *.xbps + atf_check_equal $? 0 + cd .. + xbps-install -r root -C null.conf --repository=$PWD/some_repo -A -y A-1.0_1 + atf_check_equal $? 0 + xbps-install -r root -C null.conf --repository=$PWD/some_repo -yf A-1.0_1 + atf_check_equal $? 0 + out=$(xbps-query -r root --property=automatic-install A) + atf_check_equal $out yes +} + +atf_init_test_cases() { + atf_add_test_case instmode_update + atf_add_test_case instmode_reinstall +}