libxbps: revamped trans states/cb to be more generic, not just for transactions.

This commit is contained in:
Juan RP
2011-11-11 09:41:48 +01:00
parent dc4f7af890
commit 86f1f18571
11 changed files with 191 additions and 198 deletions

View File

@@ -4,7 +4,7 @@ TOPDIR = ../..
BIN = xbps-bin
OBJS = install.o main.o remove.o show-deps.o
OBJS += show-info-files.o util.o find-files.o
OBJS += question.o fetch_cb.o trans_cb.o
OBJS += question.o fetch_cb.o state_cb.o
OBJS += check.o check_pkg_automatic.o check_pkg_files.o
OBJS += check_pkg_rundeps.o check_pkg_symlinks.o
OBJS += check_pkg_requiredby.o

View File

@@ -79,9 +79,8 @@ bool noyes(const char *, ...);
/* from fetch_cb.c */
void fetch_file_progress_cb(struct xbps_fetch_cb_data *);
/* from trans_cb.c */
void transaction_cb(struct xbps_transaction_cb_data *);
void transaction_err_cb(struct xbps_transaction_cb_data *);
/* from state_cb.c */
void state_cb(struct xbps_state_cb_data *);
/* From util.c */
int show_pkg_files(prop_dictionary_t);

View File

@@ -280,8 +280,7 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
xhp->debug = debug;
xhp->xbps_transaction_cb = transaction_cb;
xhp->xbps_transaction_err_cb = transaction_err_cb;
xhp->xbps_state_cb = state_cb;
xhp->xbps_fetch_cb = fetch_file_progress_cb;
xhp->xfcd->cookie = &xfer;
if (flags & XBPS_FLAG_VERBOSE)

View File

@@ -29,39 +29,57 @@
#include "defs.h"
void
transaction_cb(struct xbps_transaction_cb_data *xtcd)
state_cb(struct xbps_state_cb_data *xscd)
{
prop_dictionary_t pkgd;
const char *opkgver;
const char *opkgver, *state_descr, *fetchstr;
char *pkgname;
if (xtcd->desc != NULL && xtcd->pkgver == NULL) {
printf("\n%s ...\n", xtcd->desc);
if (xscd->desc != NULL && xscd->pkgver == NULL && xscd->err == 0) {
printf("\n%s ...\n", xscd->desc);
return;
}
switch (xtcd->state) {
case XBPS_TRANS_STATE_DOWNLOAD:
switch (xscd->state) {
case XBPS_STATE_DOWNLOAD:
printf("Downloading `%s' (from %s) ...\n",
xtcd->pkgver, xtcd->repourl);
xscd->pkgver, xscd->repourl);
break;
case XBPS_TRANS_STATE_VERIFY:
printf("Checking `%s' integrity ...\n", xtcd->binpkg_fname);
case XBPS_STATE_DOWNLOAD_FAIL:
state_descr = "failed to download binary package";
break;
case XBPS_TRANS_STATE_REMOVE:
printf("Removing `%s' ...\n", xtcd->pkgver);
case XBPS_STATE_VERIFY:
printf("Checking `%s' integrity ...\n", xscd->binpkg_fname);
break;
case XBPS_TRANS_STATE_PURGE:
printf("Purging `%s' ...\n", xtcd->pkgver);
case XBPS_STATE_VERIFY_FAIL:
state_descr = "failed to verify binary package SHA256";
break;
case XBPS_TRANS_STATE_CONFIGURE:
printf("Configuring `%s' ...\n", xtcd->pkgver);
case XBPS_STATE_REMOVE:
printf("Removing `%s' ...\n", xscd->pkgver);
break;
case XBPS_TRANS_STATE_REGISTER:
case XBPS_TRANS_STATE_INSTALL:
case XBPS_STATE_REMOVE_FAIL:
state_descr = "failed to remove package";
break;
case XBPS_TRANS_STATE_UPDATE:
pkgname = xbps_pkg_name(xtcd->pkgver);
case XBPS_STATE_PURGE:
printf("Purging `%s' ...\n", xscd->pkgver);
break;
case XBPS_STATE_PURGE_FAIL:
state_descr = "failed to purge package";
break;
case XBPS_STATE_CONFIGURE:
printf("Configuring `%s' ...\n", xscd->pkgver);
break;
case XBPS_STATE_CONFIGURE_FAIL:
state_descr = "failed to configure package";
break;
case XBPS_STATE_REGISTER_FAIL:
state_descr = "failed to register package";
break;
case XBPS_STATE_REGISTER:
case XBPS_STATE_INSTALL:
break;
case XBPS_STATE_UPDATE:
pkgname = xbps_pkg_name(xscd->pkgver);
if (pkgname == NULL) {
xbps_error_printf("%s: failed to alloc pkgname!\n",
__func__);
@@ -71,63 +89,34 @@ transaction_cb(struct xbps_transaction_cb_data *xtcd)
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &opkgver);
prop_object_release(pkgd);
free(pkgname);
printf("Updating `%s' to `%s'...\n", opkgver, xtcd->pkgver);
printf("Updating `%s' to `%s'...\n", opkgver, xscd->pkgver);
break;
case XBPS_TRANS_STATE_UNPACK:
printf("Unpacking `%s' (from ../%s) ...\n",
xtcd->pkgver, xtcd->binpkg_fname);
break;
case XBPS_TRANS_STATE_REPOSYNC:
printf("Synchronizing index for `%s' ...\n",
xtcd->repourl);
break;
default:
xbps_dbg_printf("%s: unknown transaction state %d %s\n",
xtcd->pkgver, xtcd->state, xtcd->desc);
break;
}
}
void
transaction_err_cb(struct xbps_transaction_cb_data *xtcd)
{
const char *state_descr = NULL;
const char *res = xbps_fetch_error_string();
switch (xtcd->state) {
case XBPS_TRANS_STATE_DOWNLOAD:
state_descr = "failed to download binary package";
break;
case XBPS_TRANS_STATE_VERIFY:
state_descr = "failed to verify binary package SHA256";
break;
case XBPS_TRANS_STATE_REMOVE:
state_descr = "failed to remove package";
break;
case XBPS_TRANS_STATE_PURGE:
state_descr = "failed to purge package";
break;
case XBPS_TRANS_STATE_CONFIGURE:
state_descr = "failed to configure package";
break;
case XBPS_TRANS_STATE_UPDATE:
case XBPS_STATE_UPDATE_FAIL:
state_descr = "failed to update package";
break;
case XBPS_TRANS_STATE_UNPACK:
case XBPS_STATE_UNPACK:
printf("Unpacking `%s' (from ../%s) ...\n",
xscd->pkgver, xscd->binpkg_fname);
break;
case XBPS_STATE_UNPACK_FAIL:
state_descr = "failed to unpack binary package";
break;
case XBPS_TRANS_STATE_REGISTER:
state_descr = "failed to register package";
case XBPS_STATE_REPOSYNC:
printf("Synchronizing index for `%s' ...\n",
xscd->repourl);
break;
case XBPS_TRANS_STATE_REPOSYNC:
case XBPS_STATE_REPOSYNC_FAIL:
fetchstr = xbps_fetch_error_string();
xbps_error_printf("Failed to sync index: %s\n",
res ? res : strerror(xtcd->err));
fetchstr ? fetchstr : strerror(xscd->err));
return;
default:
state_descr = "unknown transaction state";
xbps_dbg_printf("%s: unknown state %d %s\n",
xscd->pkgver, xscd->state, xscd->desc);
break;
}
xbps_error_printf("%s: %s: %s\n",
xtcd->pkgver, state_descr, strerror(xtcd->err));
if (state_descr != NULL && xscd->err != 0)
xbps_error_printf("%s: %s: %s\n",
xscd->pkgver, state_descr, strerror(xscd->err));
}