diff --git a/bin/xbps-install/state_cb.c b/bin/xbps-install/state_cb.c index a13ebbaf8..e40ef654e 100644 --- a/bin/xbps-install/state_cb.c +++ b/bin/xbps-install/state_cb.c @@ -155,12 +155,6 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED) printf("Fingerprint: %s\n", xscd->arg); rv = yesno("Do you want to import this public key?"); break; - case XBPS_STATE_SHOW_INSTALL_MSG: - printf("%s: post-install message:\n", xscd->arg); - printf("========================================================================\n"); - printf("%s", xscd->desc); - printf("========================================================================\n"); - break; case XBPS_STATE_UNPACK_FILE_PRESERVED: printf("%s\n", xscd->desc); break; diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index 1e207741d..f69158d4f 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -47,16 +47,80 @@ print_array(xbps_array_t a) } } +static int +show_transaction_messages(struct transaction *trans) +{ + xbps_object_t obj; + + while ((obj = xbps_object_iterator_next(trans->iter))) { + const char *pkgname = NULL; + xbps_trans_type_t ttype; + const char *key = NULL; + xbps_data_t msg, msg_pkgdb; + xbps_dictionary_t pkgdb_pkg = NULL; + const void *msgptr = NULL; + size_t msgsz = 0; + + ttype = xbps_transaction_pkg_type(obj); + switch (ttype) { + case XBPS_TRANS_REMOVE: + key = "remove-msg"; + break; + case XBPS_TRANS_UPDATE: + if (xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname)) { + /* ignore impossible errors and just show the message. */ + pkgdb_pkg = xbps_pkgdb_get_pkg(trans->xhp, pkgname); + } + /* fallthrough */ + case XBPS_TRANS_INSTALL: + key = "install-msg"; + break; + default: + continue; + } + + /* Get the message for the package in the transaction */ + msg = xbps_dictionary_get(obj, key); + if (!msg) + continue; + + msgsz = xbps_data_size(msg); + if (!msgsz) { + /* this shouldn't happen, but just ignore it */ + continue; + } + + /* Get the old message if package exists. */ + if (pkgdb_pkg) { + msg_pkgdb = xbps_dictionary_get(pkgdb_pkg, key); + if (xbps_data_equals(msg, msg_pkgdb)) + continue; + } + + msgptr = xbps_data_data_nocopy(msg); + if (!msgptr) + return EINVAL; + + if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname)) + pkgname = "?"; + + printf("[*] %s %s message:\n", pkgname, ttype2str(obj)); + fwrite(msgptr, 1, msgsz, stdout); + printf("\n\n"); + + } + xbps_object_iterator_reset(trans->iter); + return 0; +} + static void -show_actions(xbps_object_iterator_t iter) +show_dry_run_actions(struct transaction *trans) { xbps_object_t obj; - const char *repoloc, *trans, *pkgver, *arch; - uint64_t isize, dsize; - while ((obj = xbps_object_iterator_next(iter)) != NULL) { - repoloc = trans = pkgver = arch = NULL; - isize = dsize = 0; + while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) { + const char *repoloc = NULL, *pkgver = NULL, *arch = NULL; + uint64_t isize = 0, dsize = 0; xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); printf("%s %s", pkgver, ttype2str(obj)); @@ -405,7 +469,7 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d * dry-run mode, show what would be done but don't run anything. */ if (drun) { - show_actions(trans->iter); + show_dry_run_actions(trans); goto out; } /* @@ -420,6 +484,9 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d if ((rv = show_transaction_sizes(trans, maxcols)) != 0) goto out; + if ((rv = show_transaction_messages(trans)) != 0) + goto out; + fflush(stdout); /* * Ask interactively (if -y not set). diff --git a/bin/xbps-remove/main.c b/bin/xbps-remove/main.c index 7c24d614d..21636f90d 100644 --- a/bin/xbps-remove/main.c +++ b/bin/xbps-remove/main.c @@ -93,12 +93,6 @@ state_cb_rm(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED) xscd->xhp->rootdir); } break; - case XBPS_STATE_SHOW_REMOVE_MSG: - printf("%s: pre-remove message:\n", xscd->arg); - printf("========================================================================\n"); - printf("%s", xscd->desc); - printf("========================================================================\n"); - break; /* errors */ case XBPS_STATE_REMOVE_FAIL: xbps_error_printf("%s\n", xscd->desc); diff --git a/include/xbps.h.in b/include/xbps.h.in index 780673b94..a6a894d4b 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -317,8 +317,6 @@ extern "C" { * - XBPS_STATE_REPOSYNC_FAIL: syncing remote repositories has failed. * - XBPS_STATE_REPO_KEY_IMPORT: repository is signed and needs to import pubkey. * - XBPS_STATE_INVALID_DEP: package has an invalid dependency. - * - XBPS_STATE_SHOW_INSTALL_MSG: package must show a post-install message. - * - XBPS_STATE_SHOW_REMOVE_MSG: package must show a pre-remove message. * - XBPS_STATE_ALTGROUP_ADDED: package has registered an alternative group. * - XBPS_STATE_ALTGROUP_REMOVED: package has unregistered an alternative group. * - XBPS_STATE_ALTGROUP_SWITCHED: alternative group has been switched. @@ -370,8 +368,6 @@ typedef enum xbps_state { XBPS_STATE_CONFIGURE_DONE, XBPS_STATE_REPO_KEY_IMPORT, XBPS_STATE_INVALID_DEP, - XBPS_STATE_SHOW_INSTALL_MSG, - XBPS_STATE_SHOW_REMOVE_MSG, XBPS_STATE_UNPACK_FILE_PRESERVED, XBPS_STATE_PKGDB, XBPS_STATE_PKGDB_DONE, diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index 66ffc3c1a..cadb746ee 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -75,7 +75,6 @@ bool HIDDEN xbps_remove_pkg_from_array_by_pattern(xbps_array_t, const char *); bool HIDDEN xbps_remove_pkg_from_array_by_pkgver(xbps_array_t, const char *); void HIDDEN xbps_fetch_set_cache_connection(int, int); void HIDDEN xbps_fetch_unset_cache_connection(void); -int HIDDEN xbps_cb_message(struct xbps_handle *, xbps_dictionary_t, const char *); int HIDDEN xbps_entry_is_a_conf_file(xbps_dictionary_t, const char *); int HIDDEN xbps_entry_install_conf_file(struct xbps_handle *, xbps_dictionary_t, xbps_dictionary_t, struct archive_entry *, const char *, diff --git a/lib/Makefile b/lib/Makefile index 0cf6ac84f..9bb15b3ca 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -36,7 +36,7 @@ EXTOBJS = external/dewey.o external/fexec.o external/mkpath.o # libxbps OBJS = package_configure.o package_config_files.o package_orphans.o -OBJS += package_remove.o package_state.o package_msg.o +OBJS += package_remove.o package_state.o OBJS += package_unpack.o package_register.o package_script.o verifysig.o OBJS += transaction_commit.o transaction_prepare.o OBJS += transaction_ops.o transaction_store.o transaction_check_replaces.o diff --git a/lib/package_configure.c b/lib/package_configure.c index 709ed1287..8dfdb81fd 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -150,10 +150,8 @@ xbps_configure_pkg(struct xbps_handle *xhp, umask(myumask); return rv; } - if (rv == 0) - xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_DONE, 0, pkgver, NULL); + xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_DONE, 0, pkgver, NULL); umask(myumask); - /* show install-msg if exists */ - return xbps_cb_message(xhp, pkgd, "install-msg"); + return 0; } diff --git a/lib/package_msg.c b/lib/package_msg.c deleted file mode 100644 index b7bdfe4be..000000000 --- a/lib/package_msg.c +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 2014 Juan Romero Pardines. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include - -#include "xbps_api_impl.h" - -int HIDDEN -xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key) -{ - xbps_data_t msg; - const void *data; - const char *pkgver = NULL; - size_t len; - char *buf = NULL; - int rv = 0; - - assert(xhp); - assert(pkgd); - assert(key); - - xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); - - /* show install-msg if exists */ - msg = xbps_dictionary_get(pkgd, key); - if (xbps_object_type(msg) != XBPS_TYPE_DATA) - goto out; - - /* turn data from msg into a string */ - data = xbps_data_data_nocopy(msg); - len = xbps_data_size(msg); - buf = malloc(len+1); - assert(buf); - memcpy(buf, data, len); - /* terminate string */ - buf[len] = '\0'; - - /* notify client to show the post-install message */ - if (strcmp(key, "install-msg") == 0) - xbps_set_cb_state(xhp, XBPS_STATE_SHOW_INSTALL_MSG, 0, pkgver, "%s", buf); - else - xbps_set_cb_state(xhp, XBPS_STATE_SHOW_REMOVE_MSG, 0, pkgver, "%s", buf); - -out: - free(buf); - return rv; -} diff --git a/lib/package_remove.c b/lib/package_remove.c index 686a844f1..9d3a11d36 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -155,10 +155,6 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update) if (state == XBPS_PKG_STATE_HALF_REMOVED) goto purge; - /* show remove-msg if exists */ - if ((rv = xbps_cb_message(xhp, pkgd, "remove-msg")) != 0) - goto out; - /* unregister alternatives */ if (update) xbps_dictionary_set_bool(pkgd, "alternatives-update", true); diff --git a/tests/xbps/xbps-install/behaviour_tests.sh b/tests/xbps/xbps-install/behaviour_tests.sh index f4f8a4d99..b1a8a4bd5 100644 --- a/tests/xbps/xbps-install/behaviour_tests.sh +++ b/tests/xbps/xbps-install/behaviour_tests.sh @@ -175,6 +175,61 @@ reproducible_body() { atf_check_equal $? 1 } +atf_test_case install_msg + +install_msg_head() { + atf_set "descr" "xbps-install(1): show install message" +} + +install_msg_body() { + mkdir -p some_repo pkg_A + + # install will now show the message + cat <<-EOF >pkg_A/INSTALL.msg + foobar-install-msg + EOF + cd some_repo + xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + atf_check -s exit:0 \ + -o 'match:foobar-install-msg' \ + -e ignore \ + -- xbps-install -r root -C empty.conf --repository=$PWD/some_repo -y A + + # update with the same message will not show the message + cd some_repo + xbps-create -A noarch -n A-1.0_2 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + atf_check -s exit:0 \ + -o 'not-match:foobar-install-msg' \ + -e ignore \ + -- xbps-install -r root -C empty.conf --repository=$PWD/some_repo -yu + + # update with new message will show the message + cat <<-EOF >pkg_A/INSTALL.msg + fizzbuzz-install-msg + EOF + 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 .. + + atf_check -s exit:0 \ + -o 'match:fizzbuzz-install-msg' \ + -e ignore \ + -- xbps-install -r root -C empty.conf --repository=$PWD/some_repo -yu +} + atf_init_test_cases() { atf_add_test_case install_existent atf_add_test_case update_existent @@ -182,4 +237,5 @@ atf_init_test_cases() { atf_add_test_case unpacked_dep atf_add_test_case reinstall_unpacked_unpack_only atf_add_test_case reproducible + atf_add_test_case install_msg } diff --git a/tests/xbps/xbps-remove/basic_test.sh b/tests/xbps/xbps-remove/basic_test.sh index 716fb4ebe..9abcf0924 100755 --- a/tests/xbps/xbps-remove/basic_test.sh +++ b/tests/xbps/xbps-remove/basic_test.sh @@ -176,6 +176,34 @@ clean_cache_uninstalled_body() { atf_check_equal $? 0 } +atf_test_case remove_msg + +remove_msg_head() { + atf_set "descr" "xbps-rmeove(1): show remove message" +} + +remove_msg_body() { + mkdir -p some_repo pkg_A + + cat <<-EOF >pkg_A/REMOVE.msg + foobar-remove-msg + EOF + cd some_repo + xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -r root -C empty.conf -R some_repo -dvy A + atf_check_equal $? 0 + + atf_check -s exit:0 \ + -o 'match:foobar-remove-msg' \ + -e ignore \ + -- xbps-remove -r root -C empty.conf -y A +} + atf_init_test_cases() { atf_add_test_case remove_directory atf_add_test_case remove_orphans @@ -183,4 +211,5 @@ atf_init_test_cases() { atf_add_test_case clean_cache_dry_run atf_add_test_case clean_cache_dry_run_perm atf_add_test_case clean_cache_uninstalled + atf_add_test_case remove_msg }