From b874f2cdbf6e7aacd69568b898653238bbf45d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Sat, 16 Sep 2023 15:59:59 +0200 Subject: [PATCH 01/11] Expose xbps_cb_message in libxbps --- include/xbps.h.in | 10 ++++++++++ include/xbps_api_impl.h | 1 - lib/package_msg.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/xbps.h.in b/include/xbps.h.in index 780673b94..205a14986 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -1076,6 +1076,16 @@ int xbps_array_foreach_cb_multi(struct xbps_handle *xhp, int (*fn)(struct xbps_handle *, xbps_object_t obj, const char *, void *arg, bool *done), void *arg); +/** + * Prints package message. + * + * @param[in] xhp Pointer to the xbps_handle struct. + * @param[in] pkgd Package dictionary as stored in the transaction dictionary. + * @param[in] key Key of possibly existing message in \a pkgd: "install-msg" or "remove-msg". + * @return 0 for message printed, ENOENT otherwise + */ +int xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key); + /** * Match a virtual package name or pattern by looking at proplib array * of strings. 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/package_msg.c b/lib/package_msg.c index b7bdfe4be..57780f4fb 100644 --- a/lib/package_msg.c +++ b/lib/package_msg.c @@ -30,7 +30,7 @@ #include "xbps_api_impl.h" -int HIDDEN +int xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key) { xbps_data_t msg; From ee0bf136aea8623259a7341e603bde4139da1fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Sat, 24 Jul 2021 17:21:07 +0200 Subject: [PATCH 02/11] lib: display install-msgs before transaction --- bin/xbps-install/transaction.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index 1e207741d..0727d6669 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -48,7 +48,24 @@ print_array(xbps_array_t a) } static void -show_actions(xbps_object_iterator_t iter) +show_package_msgs(struct xbps_handle *xhp, xbps_object_iterator_t iter) { + xbps_dictionary_t obj; + while ((obj = xbps_object_iterator_next(iter)) != NULL) { + switch(xbps_transaction_pkg_type(obj)) { + case XBPS_TRANS_HOLD: + break; + case XBPS_TRANS_REMOVE: + xbps_cb_message(xhp, obj, "remove-msg"); + break; + default: + xbps_cb_message(xhp, obj, "install-msg"); + break; + } + } +} + +static void +show_actions(struct xbps_handle *xhp, xbps_object_iterator_t iter) { xbps_object_t obj; const char *repoloc, *trans, *pkgver, *arch; @@ -73,6 +90,8 @@ show_actions(xbps_object_iterator_t iter) printf("\n"); } + xbps_object_iterator_reset(iter); + show_package_msgs(xhp, iter); } static void @@ -124,7 +143,7 @@ show_package_list(struct transaction *trans, xbps_trans_type_t ttype, unsigned i } static int -show_transaction_sizes(struct transaction *trans, int cols) +show_transaction_sizes(struct xbps_handle *xhp, struct transaction *trans, int cols) { uint64_t dlsize = 0, instsize = 0, rmsize = 0, disk_free_size = 0; char size[8]; @@ -231,6 +250,9 @@ show_transaction_sizes(struct transaction *trans, int cols) } printf("\n"); + show_package_msgs(xhp, trans->iter); + xbps_object_iterator_reset(trans->iter); + return 0; } @@ -405,7 +427,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_actions(trans->xhp, trans->iter); goto out; } /* @@ -417,7 +439,7 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d /* * Show download/installed size for the transaction. */ - if ((rv = show_transaction_sizes(trans, maxcols)) != 0) + if ((rv = show_transaction_sizes(xhp, trans, maxcols)) != 0) goto out; fflush(stdout); From e39ae4b8b98430b8160cb2eb41ba844e3296f36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Sat, 16 Sep 2023 16:03:18 +0200 Subject: [PATCH 03/11] lib: skip install-msg seen previously --- bin/xbps-install/transaction.c | 18 +++++++++++++----- include/xbps.h.in | 7 +++++-- lib/package_configure.c | 2 +- lib/package_msg.c | 6 ++++-- lib/package_remove.c | 2 +- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index 0727d6669..f75c320e9 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -52,14 +52,22 @@ show_package_msgs(struct xbps_handle *xhp, xbps_object_iterator_t iter) { xbps_dictionary_t obj; while ((obj = xbps_object_iterator_next(iter)) != NULL) { switch(xbps_transaction_pkg_type(obj)) { - case XBPS_TRANS_HOLD: - break; case XBPS_TRANS_REMOVE: - xbps_cb_message(xhp, obj, "remove-msg"); + xbps_cb_message(xhp, obj, "remove-msg", NULL); break; - default: - xbps_cb_message(xhp, obj, "install-msg"); + case XBPS_TRANS_CONFIGURE: + // installed and transaction messages are always same, never skip + xbps_cb_message(xhp, obj, "install-msg", NULL); break; + default: + { + const char *pkgname = xbps_string_cstring_nocopy(xbps_dictionary_get(obj, "pkgname")); + xbps_dictionary_t pkgdb_pkg = pkgname ? xbps_pkgdb_get_pkg(xhp, pkgname) : NULL; + // get message from installed version of package, if any + xbps_object_t previous = pkgdb_pkg ? xbps_dictionary_get(pkgdb_pkg, "install-msg") : NULL; + xbps_cb_message(xhp, obj, "install-msg", previous); + break; + } } } } diff --git a/include/xbps.h.in b/include/xbps.h.in index 205a14986..b430639e8 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -1077,14 +1077,17 @@ int xbps_array_foreach_cb_multi(struct xbps_handle *xhp, void *arg); /** - * Prints package message. + * Prints package message. Message of earlier version of same package may be + * passed in last parameter. If current message is same as previous, message + * will not be printed. * * @param[in] xhp Pointer to the xbps_handle struct. * @param[in] pkgd Package dictionary as stored in the transaction dictionary. * @param[in] key Key of possibly existing message in \a pkgd: "install-msg" or "remove-msg". + * @param[in] message_to_skip Message of earlier version of same package or NULL. * @return 0 for message printed, ENOENT otherwise */ -int xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key); +int xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key, xbps_object_t message_to_skip); /** * Match a virtual package name or pattern by looking at proplib array diff --git a/lib/package_configure.c b/lib/package_configure.c index 709ed1287..9466ff0e4 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -155,5 +155,5 @@ xbps_configure_pkg(struct xbps_handle *xhp, umask(myumask); /* show install-msg if exists */ - return xbps_cb_message(xhp, pkgd, "install-msg"); + return xbps_cb_message(xhp, pkgd, "install-msg", NULL); } diff --git a/lib/package_msg.c b/lib/package_msg.c index 57780f4fb..36b540725 100644 --- a/lib/package_msg.c +++ b/lib/package_msg.c @@ -31,7 +31,7 @@ #include "xbps_api_impl.h" int -xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key) +xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key, xbps_object_t message_to_skip) { xbps_data_t msg; const void *data; @@ -48,8 +48,10 @@ xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key /* show install-msg if exists */ msg = xbps_dictionary_get(pkgd, key); - if (xbps_object_type(msg) != XBPS_TYPE_DATA) + if (xbps_object_type(msg) != XBPS_TYPE_DATA || (message_to_skip && xbps_object_equals(msg, message_to_skip))) { + rv = ENOENT; goto out; + } /* turn data from msg into a string */ data = xbps_data_data_nocopy(msg); diff --git a/lib/package_remove.c b/lib/package_remove.c index 686a844f1..76eaa66c3 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -156,7 +156,7 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update) goto purge; /* show remove-msg if exists */ - if ((rv = xbps_cb_message(xhp, pkgd, "remove-msg")) != 0) + if ((rv = xbps_cb_message(xhp, pkgd, "remove-msg", NULL)) != 0) goto out; /* unregister alternatives */ From 44783789bcd9db0d9f6d670b5bea95cd3b852626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Sat, 24 Jul 2021 17:21:07 +0200 Subject: [PATCH 04/11] xbps-install, -remove: change formatting of install-msgs --- bin/xbps-install/defs.h | 1 + bin/xbps-install/state_cb.c | 5 +---- bin/xbps-install/transaction.c | 15 +++++++++++++++ bin/xbps-remove/main.c | 5 +---- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/bin/xbps-install/defs.h b/bin/xbps-install/defs.h index 34680b2a9..75da0fc61 100644 --- a/bin/xbps-install/defs.h +++ b/bin/xbps-install/defs.h @@ -51,6 +51,7 @@ int install_new_pkg(struct xbps_handle *, const char *, bool); int update_pkg(struct xbps_handle *, const char *, bool); int dist_upgrade(struct xbps_handle *, unsigned int, bool, bool); int exec_transaction(struct xbps_handle *, unsigned int, bool, bool); +void print_package_msg(const struct xbps_state_cb_data *, const char *); /* from question.c */ bool yesno(const char *, ...); diff --git a/bin/xbps-install/state_cb.c b/bin/xbps-install/state_cb.c index a13ebbaf8..acfa7dcb6 100644 --- a/bin/xbps-install/state_cb.c +++ b/bin/xbps-install/state_cb.c @@ -156,10 +156,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED) 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"); + print_package_msg(xscd, "install"); break; case XBPS_STATE_UNPACK_FILE_PRESERVED: printf("%s\n", xscd->desc); diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index f75c320e9..7e65632dd 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -47,6 +47,21 @@ print_array(xbps_array_t a) } } +void +print_package_msg(const struct xbps_state_cb_data *xscd, const char *action) { + static const char bar[] = "========================================================================"; + size_t chars_print; + chars_print = printf("=== %s: %s message ", xscd->arg, action); + if (chars_print < sizeof bar) { + fputs(bar + chars_print, stdout); + } + // newline should be always printed after bar - don't move into conditional + fputs("\n", stdout); + // relying on xscd->desc containing trailing newline + fputs(xscd->desc, stdout); + puts(bar); +} + static void show_package_msgs(struct xbps_handle *xhp, xbps_object_iterator_t iter) { xbps_dictionary_t obj; diff --git a/bin/xbps-remove/main.c b/bin/xbps-remove/main.c index 7c24d614d..6c8be5ee7 100644 --- a/bin/xbps-remove/main.c +++ b/bin/xbps-remove/main.c @@ -94,10 +94,7 @@ state_cb_rm(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED) } break; case XBPS_STATE_SHOW_REMOVE_MSG: - printf("%s: pre-remove message:\n", xscd->arg); - printf("========================================================================\n"); - printf("%s", xscd->desc); - printf("========================================================================\n"); + print_package_msg(xscd, "remove"); break; /* errors */ case XBPS_STATE_REMOVE_FAIL: From 89c32afd348ca7a6db27dee0a23728fa11f5b1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Sat, 31 Jul 2021 22:38:25 +0200 Subject: [PATCH 05/11] lib: don't display package messages during transaction --- lib/package_configure.c | 6 ++---- lib/package_remove.c | 4 ---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/package_configure.c b/lib/package_configure.c index 9466ff0e4..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", NULL); + return 0; } diff --git a/lib/package_remove.c b/lib/package_remove.c index 76eaa66c3..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", NULL)) != 0) - goto out; - /* unregister alternatives */ if (update) xbps_dictionary_set_bool(pkgd, "alternatives-update", true); From 2a0d57f99c1a4c440c5e073c08d8108af49c6f28 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Sun, 17 Sep 2023 19:56:41 +0200 Subject: [PATCH 06/11] bin/xbps-{install,remove}: cleanup transaction code function arguments --- bin/xbps-install/transaction.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index 7e65632dd..def93764a 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -88,15 +88,13 @@ show_package_msgs(struct xbps_handle *xhp, xbps_object_iterator_t iter) { } static void -show_actions(struct xbps_handle *xhp, 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)); @@ -113,8 +111,8 @@ show_actions(struct xbps_handle *xhp, xbps_object_iterator_t iter) printf("\n"); } - xbps_object_iterator_reset(iter); - show_package_msgs(xhp, iter); + show_package_msgs(trans->xhp, trans->iter); + xbps_object_iterator_reset(trans->iter); } static void @@ -166,7 +164,7 @@ show_package_list(struct transaction *trans, xbps_trans_type_t ttype, unsigned i } static int -show_transaction_sizes(struct xbps_handle *xhp, struct transaction *trans, int cols) +show_transaction_sizes(struct transaction *trans, int cols) { uint64_t dlsize = 0, instsize = 0, rmsize = 0, disk_free_size = 0; char size[8]; @@ -450,7 +448,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->xhp, trans->iter); + show_dry_run_actions(trans); goto out; } /* @@ -462,7 +460,7 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d /* * Show download/installed size for the transaction. */ - if ((rv = show_transaction_sizes(xhp, trans, maxcols)) != 0) + if ((rv = show_transaction_sizes(trans, maxcols)) != 0) goto out; fflush(stdout); From e2600c2e47e8c9fc195897f8bdb3f97172f7acfb Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Sun, 17 Sep 2023 19:58:44 +0200 Subject: [PATCH 07/11] lib: remove xbps_cb_message and message states --- include/xbps.h.in | 17 ----------- lib/Makefile | 2 +- lib/package_msg.c | 74 ----------------------------------------------- 3 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 lib/package_msg.c diff --git a/include/xbps.h.in b/include/xbps.h.in index b430639e8..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, @@ -1076,19 +1072,6 @@ int xbps_array_foreach_cb_multi(struct xbps_handle *xhp, int (*fn)(struct xbps_handle *, xbps_object_t obj, const char *, void *arg, bool *done), void *arg); -/** - * Prints package message. Message of earlier version of same package may be - * passed in last parameter. If current message is same as previous, message - * will not be printed. - * - * @param[in] xhp Pointer to the xbps_handle struct. - * @param[in] pkgd Package dictionary as stored in the transaction dictionary. - * @param[in] key Key of possibly existing message in \a pkgd: "install-msg" or "remove-msg". - * @param[in] message_to_skip Message of earlier version of same package or NULL. - * @return 0 for message printed, ENOENT otherwise - */ -int xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key, xbps_object_t message_to_skip); - /** * Match a virtual package name or pattern by looking at proplib array * of strings. 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_msg.c b/lib/package_msg.c deleted file mode 100644 index 36b540725..000000000 --- a/lib/package_msg.c +++ /dev/null @@ -1,74 +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 -xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key, xbps_object_t message_to_skip) -{ - 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 || (message_to_skip && xbps_object_equals(msg, message_to_skip))) { - rv = ENOENT; - 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; -} From 8352e086a8c05654d401dd7b30cccdbb1c8d713a Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Sun, 17 Sep 2023 20:00:07 +0200 Subject: [PATCH 08/11] bin/xbps-remove: remove message callbacks --- bin/xbps-remove/main.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/xbps-remove/main.c b/bin/xbps-remove/main.c index 6c8be5ee7..21636f90d 100644 --- a/bin/xbps-remove/main.c +++ b/bin/xbps-remove/main.c @@ -93,9 +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: - print_package_msg(xscd, "remove"); - break; /* errors */ case XBPS_STATE_REMOVE_FAIL: xbps_error_printf("%s\n", xscd->desc); From 52960e8dae57b14318381caf5a03733c04b48881 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Sun, 17 Sep 2023 20:00:31 +0200 Subject: [PATCH 09/11] bin/xbps-install: remove message callbacks --- bin/xbps-install/state_cb.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/xbps-install/state_cb.c b/bin/xbps-install/state_cb.c index acfa7dcb6..e40ef654e 100644 --- a/bin/xbps-install/state_cb.c +++ b/bin/xbps-install/state_cb.c @@ -155,9 +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: - print_package_msg(xscd, "install"); - break; case XBPS_STATE_UNPACK_FILE_PRESERVED: printf("%s\n", xscd->desc); break; From 1ac569888db4cd5482becad9c2286ee518463ec9 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Sun, 17 Sep 2023 20:01:48 +0200 Subject: [PATCH 10/11] bin/xbps-{install,remove}: print install/remove messages --- bin/xbps-install/defs.h | 1 - bin/xbps-install/transaction.c | 104 ++++++++++++++++++++------------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/bin/xbps-install/defs.h b/bin/xbps-install/defs.h index 75da0fc61..34680b2a9 100644 --- a/bin/xbps-install/defs.h +++ b/bin/xbps-install/defs.h @@ -51,7 +51,6 @@ int install_new_pkg(struct xbps_handle *, const char *, bool); int update_pkg(struct xbps_handle *, const char *, bool); int dist_upgrade(struct xbps_handle *, unsigned int, bool, bool); int exec_transaction(struct xbps_handle *, unsigned int, bool, bool); -void print_package_msg(const struct xbps_state_cb_data *, const char *); /* from question.c */ bool yesno(const char *, ...); diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index def93764a..f69158d4f 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -47,44 +47,70 @@ print_array(xbps_array_t a) } } -void -print_package_msg(const struct xbps_state_cb_data *xscd, const char *action) { - static const char bar[] = "========================================================================"; - size_t chars_print; - chars_print = printf("=== %s: %s message ", xscd->arg, action); - if (chars_print < sizeof bar) { - fputs(bar + chars_print, stdout); - } - // newline should be always printed after bar - don't move into conditional - fputs("\n", stdout); - // relying on xscd->desc containing trailing newline - fputs(xscd->desc, stdout); - puts(bar); -} +static int +show_transaction_messages(struct transaction *trans) +{ + xbps_object_t obj; -static void -show_package_msgs(struct xbps_handle *xhp, xbps_object_iterator_t iter) { - xbps_dictionary_t obj; - while ((obj = xbps_object_iterator_next(iter)) != NULL) { - switch(xbps_transaction_pkg_type(obj)) { - case XBPS_TRANS_REMOVE: - xbps_cb_message(xhp, obj, "remove-msg", NULL); - break; - case XBPS_TRANS_CONFIGURE: - // installed and transaction messages are always same, never skip - xbps_cb_message(xhp, obj, "install-msg", NULL); - break; - default: - { - const char *pkgname = xbps_string_cstring_nocopy(xbps_dictionary_get(obj, "pkgname")); - xbps_dictionary_t pkgdb_pkg = pkgname ? xbps_pkgdb_get_pkg(xhp, pkgname) : NULL; - // get message from installed version of package, if any - xbps_object_t previous = pkgdb_pkg ? xbps_dictionary_get(pkgdb_pkg, "install-msg") : NULL; - xbps_cb_message(xhp, obj, "install-msg", previous); - break; - } + 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 @@ -111,8 +137,6 @@ show_dry_run_actions(struct transaction *trans) printf("\n"); } - show_package_msgs(trans->xhp, trans->iter); - xbps_object_iterator_reset(trans->iter); } static void @@ -271,9 +295,6 @@ show_transaction_sizes(struct transaction *trans, int cols) } printf("\n"); - show_package_msgs(xhp, trans->iter); - xbps_object_iterator_reset(trans->iter); - return 0; } @@ -463,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). From efa897394c9d3ee86e687fbb4c03a407eff6f722 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Sun, 17 Sep 2023 20:02:11 +0200 Subject: [PATCH 11/11] tests: add tests for install and remove messages --- tests/xbps/xbps-install/behaviour_tests.sh | 56 ++++++++++++++++++++++ tests/xbps/xbps-remove/basic_test.sh | 29 +++++++++++ 2 files changed, 85 insertions(+) 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 }