Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print install and remove messages below transaction summary #572

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
6 changes: 0 additions & 6 deletions bin/xbps-install/state_cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
81 changes: 74 additions & 7 deletions bin/xbps-install/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
/*
Expand All @@ -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).
Expand Down
6 changes: 0 additions & 6 deletions bin/xbps-remove/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions include/xbps.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion include/xbps_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *,
Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions lib/package_configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
72 changes: 0 additions & 72 deletions lib/package_msg.c

This file was deleted.

4 changes: 0 additions & 4 deletions lib/package_remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
56 changes: 56 additions & 0 deletions tests/xbps/xbps-install/behaviour_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,67 @@ 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
atf_add_test_case update_unpacked
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
}
29 changes: 29 additions & 0 deletions tests/xbps/xbps-remove/basic_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,40 @@ 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
atf_add_test_case clean_cache
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
}
Loading