@@ -47,44 +47,70 @@ print_array(xbps_array_t a)
4747 }
4848}
4949
50- void
51- print_package_msg (const struct xbps_state_cb_data * xscd , const char * action ) {
52- static const char bar [] = "========================================================================" ;
53- size_t chars_print ;
54- chars_print = printf ("=== %s: %s message " , xscd -> arg , action );
55- if (chars_print < sizeof bar ) {
56- fputs (bar + chars_print , stdout );
57- }
58- // newline should be always printed after bar - don't move into conditional
59- fputs ("\n" , stdout );
60- // relying on xscd->desc containing trailing newline
61- fputs (xscd -> desc , stdout );
62- puts (bar );
63- }
50+ static int
51+ show_transaction_messages (struct transaction * trans )
52+ {
53+ xbps_object_t obj ;
6454
65- static void
66- show_package_msgs (struct xbps_handle * xhp , xbps_object_iterator_t iter ) {
67- xbps_dictionary_t obj ;
68- while ((obj = xbps_object_iterator_next (iter )) != NULL ) {
69- switch (xbps_transaction_pkg_type (obj )) {
70- case XBPS_TRANS_REMOVE :
71- xbps_cb_message (xhp , obj , "remove-msg" , NULL );
72- break ;
73- case XBPS_TRANS_CONFIGURE :
74- // installed and transaction messages are always same, never skip
75- xbps_cb_message (xhp , obj , "install-msg" , NULL );
76- break ;
77- default :
78- {
79- const char * pkgname = xbps_string_cstring_nocopy (xbps_dictionary_get (obj , "pkgname" ));
80- xbps_dictionary_t pkgdb_pkg = pkgname ? xbps_pkgdb_get_pkg (xhp , pkgname ) : NULL ;
81- // get message from installed version of package, if any
82- xbps_object_t previous = pkgdb_pkg ? xbps_dictionary_get (pkgdb_pkg , "install-msg" ) : NULL ;
83- xbps_cb_message (xhp , obj , "install-msg" , previous );
84- break ;
85- }
55+ while ((obj = xbps_object_iterator_next (trans -> iter ))) {
56+ const char * pkgname = NULL ;
57+ xbps_trans_type_t ttype ;
58+ const char * key = NULL ;
59+ xbps_data_t msg , msg_pkgdb ;
60+ xbps_dictionary_t pkgdb_pkg = NULL ;
61+ const void * msgptr = NULL ;
62+ size_t msgsz = 0 ;
63+
64+ ttype = xbps_transaction_pkg_type (obj );
65+ switch (ttype ) {
66+ case XBPS_TRANS_REMOVE :
67+ key = "remove-msg" ;
68+ break ;
69+ case XBPS_TRANS_UPDATE :
70+ if (xbps_dictionary_get_cstring_nocopy (obj , "pkgname" , & pkgname )) {
71+ /* ignore impossible errors and just show the message. */
72+ pkgdb_pkg = xbps_pkgdb_get_pkg (trans -> xhp , pkgname );
73+ }
74+ /* fallthrough */
75+ case XBPS_TRANS_INSTALL :
76+ key = "install-msg" ;
77+ break ;
78+ default :
79+ continue ;
80+ }
81+
82+ /* Get the message for the package in the transaction */
83+ msg = xbps_dictionary_get (obj , key );
84+ if (!msg )
85+ continue ;
86+
87+ msgsz = xbps_data_size (msg );
88+ if (!msgsz ) {
89+ /* this shouldn't happen, but just ignore it */
90+ continue ;
8691 }
92+
93+ /* Get the old message if package exists. */
94+ if (pkgdb_pkg ) {
95+ msg_pkgdb = xbps_dictionary_get (pkgdb_pkg , key );
96+ if (xbps_data_equals (msg , msg_pkgdb ))
97+ continue ;
98+ }
99+
100+ msgptr = xbps_data_data_nocopy (msg );
101+ if (!msgptr )
102+ return EINVAL ;
103+
104+ if (!xbps_dictionary_get_cstring_nocopy (obj , "pkgname" , & pkgname ))
105+ pkgname = "?" ;
106+
107+ printf ("[*] %s %s message:\n" , pkgname , ttype2str (obj ));
108+ fwrite (msgptr , 1 , msgsz , stdout );
109+ printf ("\n\n" );
110+
87111 }
112+ xbps_object_iterator_reset (trans -> iter );
113+ return 0 ;
88114}
89115
90116static void
@@ -104,8 +130,6 @@ show_dry_run_actions(struct transaction *trans)
104130
105131 printf ("%s %s %s %s %ju %ju\n" , pkgver , ttype2str (obj ), arch ? arch : "-" , repoloc ? repoloc : "-" , isize , dsize );
106132 }
107- show_package_msgs (trans -> xhp , trans -> iter );
108- xbps_object_iterator_reset (trans -> iter );
109133}
110134
111135static void
@@ -264,9 +288,6 @@ show_transaction_sizes(struct transaction *trans, int cols)
264288 }
265289 printf ("\n" );
266290
267- show_package_msgs (xhp , trans -> iter );
268- xbps_object_iterator_reset (trans -> iter );
269-
270291 return 0 ;
271292}
272293
@@ -456,6 +477,9 @@ exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool d
456477 if ((rv = show_transaction_sizes (trans , maxcols )) != 0 )
457478 goto out ;
458479
480+ if ((rv = show_transaction_messages (trans )) != 0 )
481+ goto out ;
482+
459483 fflush (stdout );
460484 /*
461485 * Ask interactively (if -y not set).
0 commit comments