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

@ -4,7 +4,7 @@ TOPDIR = ../..
BIN = xbps-bin BIN = xbps-bin
OBJS = install.o main.o remove.o show-deps.o OBJS = install.o main.o remove.o show-deps.o
OBJS += show-info-files.o util.o find-files.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.o check_pkg_automatic.o check_pkg_files.o
OBJS += check_pkg_rundeps.o check_pkg_symlinks.o OBJS += check_pkg_rundeps.o check_pkg_symlinks.o
OBJS += check_pkg_requiredby.o OBJS += check_pkg_requiredby.o

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

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

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

@ -4,7 +4,7 @@ TOPDIR = ../..
BIN = xbps-repo BIN = xbps-repo
OBJS = main.o index.o show.o find-files.o OBJS = main.o index.o show.o find-files.o
OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o
OBJS += ../xbps-bin/trans_cb.o OBJS += ../xbps-bin/state_cb.o
MAN = $(BIN).8 MAN = $(BIN).8
include $(TOPDIR)/bin/prog.mk include $(TOPDIR)/bin/prog.mk

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

@ -55,7 +55,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.3" #define XBPS_PKGINDEX_VERSION "1.3"
#define XBPS_API_VERSION "20111110" #define XBPS_API_VERSION "20111111"
#define XBPS_VERSION "0.11.0" #define XBPS_VERSION "0.11.0"
/** /**
@ -156,73 +156,82 @@ void xbps_warn_printf(const char *, ...);
/*@{*/ /*@{*/
/** /**
* @enum trans_state_t * @enum xbps_state_t
* *
* Integer representing the transaction state. Possible values: * Integer representing the xbps callback returned state. Possible values:
* *
* <b>XBPS_TRANS_STATE_UKKNOWN</b>: unknown, transaction hasn't been * <b>XBPS_STATE_UKKNOWN</b>: unknown, state hasn't been
* prepared or some unknown error ocurred. * prepared or some unknown error ocurred.
* *
* <b>XBPS_TRANS_STATE_DOWNLOAD</b>: a binary package is being downloaded. * <b>XBPS_STATE_DOWNLOAD</b>: a binary package is being downloaded.
* *
* <b>XBPS_TRANS_STATE_VERIFY</b>: a binary package is being verified. * <b>XBPS_STATE_VERIFY</b>: a binary package is being verified.
* *
* <b>XBPS_TRANS_STATE_REMOVE</b>: a package is being removed. * <b>XBPS_STATE_REMOVE</b>: a package is being removed.
* *
* <b>XBPS_TRANS_STATE_PURGE</b>: a package is being purged. * <b>XBPS_STATE_PURGE</b>: a package is being purged.
* *
* <b>XBPS_TRANS_STATE_REPLACE</b>: a package is being replaced. * <b>XBPS_STATE_REPLACE</b>: a package is being replaced.
* *
* <b>XBPS_TRANS_STATE_INSTALL</b>: a package is being installed. * <b>XBPS_STATE_INSTALL</b>: a package is being installed.
* *
* <b>XBPS_TRANS_STATE_UPDATE</b>: a package is being updated. * <b>XBPS_STATE_UPDATE</b>: a package is being updated.
* *
* <b>XBPS_TRANS_STATE_UNPACK</b>: a package is being unpacked. * <b>XBPS_STATE_UNPACK</b>: a package is being unpacked.
* *
* <b>XBPS_TRANS_STATE_CONFIGURE</b>: a package is being configured. * <b>XBPS_STATE_CONFIGURE</b>: a package is being configured.
* *
* <b>XBPS_TRANS_STATE_REGISTER</b>: a package is being registered. * <b>XBPS_STATE_REGISTER</b>: a package is being registered.
* *
* <b>XBPS_TRANS_STATE_REPOSYNC</b>: a remote repository's * <b>XBPS_STATE_REPOSYNC</b>: a remote repository's
* pkg index is being synchronized. * pkg index is being synchronized.
*/ */
typedef enum trans_state { typedef enum xbps_state {
XBPS_TRANS_STATE_UNKNOWN = 0, XBPS_STATE_UNKNOWN = 0,
XBPS_TRANS_STATE_DOWNLOAD, XBPS_STATE_DOWNLOAD,
XBPS_TRANS_STATE_VERIFY, XBPS_STATE_VERIFY,
XBPS_TRANS_STATE_REMOVE, XBPS_STATE_REMOVE,
XBPS_TRANS_STATE_PURGE, XBPS_STATE_PURGE,
XBPS_TRANS_STATE_REPLACE, XBPS_STATE_REPLACE,
XBPS_TRANS_STATE_INSTALL, XBPS_STATE_INSTALL,
XBPS_TRANS_STATE_UPDATE, XBPS_STATE_UPDATE,
XBPS_TRANS_STATE_UNPACK, XBPS_STATE_UNPACK,
XBPS_TRANS_STATE_CONFIGURE, XBPS_STATE_CONFIGURE,
XBPS_TRANS_STATE_REGISTER, XBPS_STATE_REGISTER,
XBPS_TRANS_STATE_REPOSYNC XBPS_STATE_REPOSYNC,
} trans_state_t; XBPS_STATE_VERIFY_FAIL,
XBPS_STATE_DOWNLOAD_FAIL,
XBPS_STATE_REMOVE_FAIL,
XBPS_STATE_PURGE_FAIL,
XBPS_STATE_CONFIGURE_FAIL,
XBPS_STATE_UPDATE_FAIL,
XBPS_STATE_UNPACK_FAIL,
XBPS_STATE_REGISTER_FAIL,
XBPS_STATE_REPOSYNC_FAIL
} xbps_state_t;
/** /**
* @struct xbps_transaction_cb_data xbps_api.h "xbps_api.h" * @struct xbps_cb_data xbps_api.h "xbps_api.h"
* @brief Structure to be passed as argument to the transaction * @brief Structure to be passed as argument to the state
* function callbacks. * function callbacks.
*/ */
struct xbps_transaction_cb_data { struct xbps_state_cb_data {
/** /**
* @var state * @var state
* *
* Transaction's state (set internally, read-only). * Returned xbps state (set internally, read-only).
*/ */
trans_state_t state; xbps_state_t state;
/** /**
* @var desc * @var desc
* *
* Transaction's string description (set internally, read-only). * XBPS state string description (set internally, read-only).
*/ */
const char *desc; const char *desc;
/** /**
* @var pkgver * @var pkgver
* *
* Transaction's current pkgname/version string * XBPS state current pkgname/version string
* (set internally, read-only). * (set internally, read-only).
*/ */
const char *pkgver; const char *pkgver;
@ -241,7 +250,7 @@ struct xbps_transaction_cb_data {
/** /**
* @var err * @var err
* *
* Transaction error value (set internally, read-only). * XBPS state error value (set internally, read-only).
*/ */
int err; int err;
/** /**
@ -404,27 +413,19 @@ struct xbps_handle {
*/ */
prop_dictionary_t regpkgdb_dictionary; prop_dictionary_t regpkgdb_dictionary;
/** /**
* @var xbps_transaction_cb * @var xbps_state_cb
* *
* Pointer to the supplifed function callback to be used * Pointer to the supplifed function callback to be used
* in a transaction. * in the XBPS possible states.
*/ */
void (*xbps_transaction_cb)(struct xbps_transaction_cb_data *); void (*xbps_state_cb)(struct xbps_state_cb_data *);
/** /**
* @var xbps_transaction_err_cb * @var xscd
* *
* Pointer the the supplied function callback to be used in * Pointer to a xbps_state_cb_data structure. It's allocated by
* a transaction when an error happens. * xbps_handle_alloc(), set internally.
*/ */
void (*xbps_transaction_err_cb)(struct xbps_transaction_cb_data *); struct xbps_state_cb_data *xscd;
/**
* @var xtcd
*
* Pointer to a xbps_transaction_cb_data structure, to be passed as
* argument to the \a xbps_transaction_cb and
* \a xbps_transaction_err_cb function callbacks.
*/
struct xbps_transaction_cb_data *xtcd;
/** /**
* @var xbps_unpack_cb * @var xbps_unpack_cb
* *

@ -207,8 +207,8 @@ xbps_end(struct xbps_handle *xh)
free(xh->xfcd); free(xh->xfcd);
if (xh->xucd != NULL) if (xh->xucd != NULL)
free(xh->xucd); free(xh->xucd);
if (xh->xtcd != NULL) if (xh->xscd != NULL)
free(xh->xtcd); free(xh->xscd);
free(xh); free(xh);
xh = NULL; xh = NULL;
@ -227,24 +227,24 @@ xbps_handle_alloc(void)
{ {
struct xbps_handle *xh; struct xbps_handle *xh;
xh = calloc(1, sizeof(struct xbps_handle)); xh = malloc(sizeof *xh);
if (xh == NULL) if (xh == NULL)
return NULL; return NULL;
xh->xtcd = calloc(1, sizeof(struct xbps_transaction_cb_data)); xh->xscd = malloc(sizeof *xh->xscd);
if (xh->xtcd == NULL) { if (xh->xscd == NULL) {
free(xh); free(xh);
return NULL; return NULL;
} }
xh->xucd = calloc(1, sizeof(struct xbps_unpack_cb_data)); xh->xucd = malloc(sizeof *xh->xucd);
if (xh->xucd == NULL) { if (xh->xucd == NULL) {
free(xh->xtcd); free(xh->xscd);
free(xh); free(xh);
return NULL; return NULL;
} }
xh->xfcd = calloc(1, sizeof(struct xbps_fetch_cb_data)); xh->xfcd = malloc(sizeof *xh->xfcd);
if (xh->xfcd == NULL) { if (xh->xfcd == NULL) {
free(xh->xucd); free(xh->xucd);
free(xh->xtcd); free(xh->xscd);
free(xh); free(xh);
return NULL; return NULL;
} }

@ -120,13 +120,14 @@ xbps_configure_pkg(const char *pkgname,
if (pkgver == NULL) if (pkgver == NULL)
return ENOMEM; return ENOMEM;
if (xhp->xbps_transaction_cb) { if (xhp->xbps_state_cb) {
xhp->xtcd->desc = NULL; xhp->xscd->desc = NULL;
xhp->xtcd->binpkg_fname = NULL; xhp->xscd->binpkg_fname = NULL;
xhp->xtcd->repourl = NULL; xhp->xscd->repourl = NULL;
xhp->xtcd->state = XBPS_TRANS_STATE_CONFIGURE; xhp->xscd->err = 0;
xhp->xtcd->pkgver = pkgver; xhp->xscd->state = XBPS_STATE_CONFIGURE;
xhp->xbps_transaction_cb(xhp->xtcd); xhp->xscd->pkgver = pkgver;
xhp->xbps_state_cb(xhp->xscd);
} }
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL", buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
@ -166,5 +167,12 @@ xbps_configure_pkg(const char *pkgname,
XBPS_PKG_STATE_INSTALLED); XBPS_PKG_STATE_INSTALLED);
free(pkgver); free(pkgver);
if (rv != 0 && xhp->xbps_state_cb) {
xhp->xscd->pkgver = pkgver;
xhp->xscd->err = rv;
xhp->xscd->state = XBPS_STATE_CONFIGURE_FAIL;
xhp->xbps_state_cb(xhp->xscd);
}
return rv; return rv;
} }

@ -166,24 +166,24 @@ xbps_repository_sync_pkg_index(const char *uri)
fetch_outputdir = metadir; fetch_outputdir = metadir;
/* reposync start cb */ /* reposync start cb */
if (xhp->xbps_transaction_cb) { if (xhp->xbps_state_cb) {
xhp->xtcd->state = XBPS_TRANS_STATE_REPOSYNC; xhp->xscd->state = XBPS_STATE_REPOSYNC;
xhp->xtcd->repourl = uri; xhp->xscd->repourl = uri;
xhp->xbps_transaction_cb(xhp->xtcd); xhp->xbps_state_cb(xhp->xscd);
} }
/* /*
* Download index.plist file from repository. * Download index.plist file from repository.
*/ */
if (xbps_fetch_file(rpidx, fetch_outputdir, true, NULL) == -1) { if (xbps_fetch_file(rpidx, fetch_outputdir, true, NULL) == -1) {
/* reposync error cb */ /* reposync error cb */
if (xhp->xbps_transaction_err_cb) { if (xhp->xbps_state_cb) {
xhp->xtcd->state = XBPS_TRANS_STATE_REPOSYNC; xhp->xscd->state = XBPS_STATE_REPOSYNC_FAIL;
xhp->xtcd->repourl = uri; xhp->xscd->repourl = uri;
if (fetchLastErrCode != 0) if (fetchLastErrCode != 0)
xhp->xtcd->err = fetchLastErrCode; xhp->xscd->err = fetchLastErrCode;
else else
xhp->xtcd->err = errno; xhp->xscd->err = errno;
xhp->xbps_transaction_err_cb(xhp->xtcd); xhp->xbps_state_cb(xhp->xscd);
} }
rv = -1; rv = -1;
goto out; goto out;

@ -35,33 +35,33 @@
#include "xbps_api_impl.h" #include "xbps_api_impl.h"
#define RUN_TRANS_CB(s, d, p, bf, burl) \ #define RUN_STATE_CB(s, d, p, bf, burl) \
do { \ do { \
if (xhp->xbps_transaction_cb != NULL) { \ if (xhp->xbps_state_cb != NULL) { \
xhp->xtcd->state = s; \ xhp->xscd->state = s; \
xhp->xtcd->desc = d; \ xhp->xscd->desc = d; \
xhp->xtcd->pkgver = p; \ xhp->xscd->pkgver = p; \
xhp->xtcd->binpkg_fname = bf; \ xhp->xscd->binpkg_fname = bf; \
xhp->xtcd->repourl = burl; \ xhp->xscd->repourl = burl; \
(*xhp->xbps_transaction_cb)(xhp->xtcd); \ (*xhp->xbps_state_cb)(xhp->xscd); \
} \ } \
} while (0) } while (0)
#define RUN_TRANS_ERR_CB(s, p, r) \ #define RUN_STATE_ERR_CB(s, p, r) \
do { \ do { \
if (xhp->xbps_transaction_err_cb != NULL) { \ if (xhp->xbps_state_cb != NULL) { \
xhp->xtcd->state = s; \ xhp->xscd->state = s; \
xhp->xtcd->pkgver = p; \ xhp->xscd->pkgver = p; \
xhp->xtcd->err = r; \ xhp->xscd->err = r; \
(*xhp->xbps_transaction_err_cb)(xhp->xtcd); \ (*xhp->xbps_state_cb)(xhp->xscd); \
} \ } \
} while (0) } while (0)
static int static int
check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter) check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
{ {
prop_object_t obj; prop_object_t obj;
const char *pkgver, *repoloc, *filename, *sha256, *trans; const char *pkgver, *repoloc, *filen, *sha256, *trans;
char *binfile; char *binfile;
int rv = 0; int rv = 0;
@ -75,8 +75,8 @@ check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
assert(repoloc != NULL); assert(repoloc != NULL);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
assert(pkgver != NULL); assert(pkgver != NULL);
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename); prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
assert(filename != NULL); assert(filen != NULL);
prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj,
"filename-sha256", &sha256); "filename-sha256", &sha256);
assert(sha256 != NULL); assert(sha256 != NULL);
@ -86,12 +86,11 @@ check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
rv = EINVAL; rv = EINVAL;
break; break;
} }
RUN_TRANS_CB(XBPS_TRANS_STATE_VERIFY, RUN_STATE_CB(XBPS_STATE_VERIFY, NULL, pkgver, filen, repoloc);
NULL, pkgver, filename, repoloc);
rv = xbps_file_hash_check(binfile, sha256); rv = xbps_file_hash_check(binfile, sha256);
if (rv != 0) { if (rv != 0) {
free(binfile); free(binfile);
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_VERIFY, pkgver, rv); RUN_STATE_ERR_CB(XBPS_STATE_VERIFY_FAIL, pkgver, rv);
break; break;
} }
free(binfile); free(binfile);
@ -105,7 +104,7 @@ static int
download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter) download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
{ {
prop_object_t obj; prop_object_t obj;
const char *pkgver, *repoloc, *filename, *trans; const char *pkgver, *repoloc, *filen, *trans;
char *binfile; char *binfile;
int rv = 0; int rv = 0;
@ -119,8 +118,8 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
assert(repoloc != NULL); assert(repoloc != NULL);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
assert(pkgver != NULL); assert(pkgver != NULL);
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename); prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
assert(filename != NULL); assert(filen != NULL);
binfile = xbps_path_from_repository_uri(obj, repoloc); binfile = xbps_path_from_repository_uri(obj, repoloc);
if (binfile == NULL) { if (binfile == NULL) {
@ -147,15 +146,15 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
rv = errno; rv = errno;
break; break;
} }
RUN_TRANS_CB(XBPS_TRANS_STATE_DOWNLOAD, RUN_STATE_CB(XBPS_STATE_DOWNLOAD, NULL, pkgver, filen, repoloc);
NULL, pkgver, filename, repoloc);
/* /*
* Fetch binary package. * Fetch binary package.
*/ */
rv = xbps_fetch_file(binfile, rv = xbps_fetch_file(binfile,
prop_string_cstring_nocopy(xhp->cachedir), false, NULL); prop_string_cstring_nocopy(xhp->cachedir), false, NULL);
if (rv == -1) { if (rv == -1) {
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_DOWNLOAD, pkgver, errno); RUN_STATE_ERR_CB(XBPS_STATE_DOWNLOAD_FAIL,
pkgver, errno);
free(binfile); free(binfile);
break; break;
} }
@ -186,14 +185,14 @@ xbps_transaction_commit(prop_dictionary_t transd)
/* /*
* Download binary packages (if they come from a remote repository). * Download binary packages (if they come from a remote repository).
*/ */
RUN_TRANS_CB(XBPS_TRANS_STATE_DOWNLOAD, RUN_STATE_CB(XBPS_STATE_DOWNLOAD,
"[*] Downloading binary packages", NULL, NULL, NULL); "[*] Downloading binary packages", NULL, NULL, NULL);
if ((rv = download_binpkgs(xhp, iter)) != 0) if ((rv = download_binpkgs(xhp, iter)) != 0)
goto out; goto out;
/* /*
* Check SHA256 hashes for binary packages in transaction. * Check SHA256 hashes for binary packages in transaction.
*/ */
RUN_TRANS_CB(XBPS_TRANS_STATE_VERIFY, RUN_STATE_CB(XBPS_STATE_VERIFY,
"[*] Verifying binary package integrity", NULL, NULL, NULL); "[*] Verifying binary package integrity", NULL, NULL, NULL);
if ((rv = check_binpkgs_hash(xhp, iter)) != 0) if ((rv = check_binpkgs_hash(xhp, iter)) != 0)
goto out; goto out;
@ -201,7 +200,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
* Install, update, configure or remove packages as specified * Install, update, configure or remove packages as specified
* in the transaction dictionary. * in the transaction dictionary.
*/ */
RUN_TRANS_CB(XBPS_TRANS_STATE_INSTALL, RUN_STATE_CB(XBPS_STATE_INSTALL,
"[*] Running transaction tasks", NULL, NULL, NULL); "[*] Running transaction tasks", NULL, NULL, NULL);
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
@ -218,21 +217,21 @@ xbps_transaction_commit(prop_dictionary_t transd)
*/ */
prop_dictionary_get_bool(obj, "remove-and-update", prop_dictionary_get_bool(obj, "remove-and-update",
&update); &update);
RUN_TRANS_CB(XBPS_TRANS_STATE_REMOVE, RUN_STATE_CB(XBPS_STATE_REMOVE,
NULL, pkgver, NULL, NULL); NULL, pkgver, NULL, NULL);
rv = xbps_remove_pkg(pkgname, version, update); rv = xbps_remove_pkg(pkgname, version, update);
if (rv != 0) { if (rv != 0) {
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_REMOVE, RUN_STATE_ERR_CB(XBPS_STATE_REMOVE_FAIL,
pkgver, rv); pkgver, rv);
goto out; goto out;
} }
if (update) if (update)
continue; continue;
RUN_TRANS_CB(XBPS_TRANS_STATE_PURGE, RUN_STATE_CB(XBPS_STATE_PURGE,
NULL, pkgver, NULL, NULL); NULL, pkgver, NULL, NULL);
if ((rv = xbps_purge_pkg(pkgname, false)) != 0) { if ((rv = xbps_purge_pkg(pkgname, false)) != 0) {
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_PURGE, RUN_STATE_ERR_CB(XBPS_STATE_PURGE_FAIL,
pkgver, rv); pkgver, rv);
goto out; goto out;
} }
@ -242,7 +241,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
*/ */
rv = xbps_configure_pkg(pkgname, version, false, false); rv = xbps_configure_pkg(pkgname, version, false, false);
if (rv != 0) { if (rv != 0) {
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_CONFIGURE, RUN_STATE_ERR_CB(XBPS_STATE_CONFIGURE_FAIL,
pkgver, rv); pkgver, rv);
goto out; goto out;
} }
@ -258,11 +257,11 @@ xbps_transaction_commit(prop_dictionary_t transd)
* Update a package: execute pre-remove * Update a package: execute pre-remove
* action if found before unpacking. * action if found before unpacking.
*/ */
RUN_TRANS_CB(XBPS_TRANS_STATE_UPDATE, RUN_STATE_CB(XBPS_STATE_UPDATE,
NULL, pkgver, filen, NULL); NULL, pkgver, filen, NULL);
rv = xbps_remove_pkg(pkgname, version, true); rv = xbps_remove_pkg(pkgname, version, true);
if (rv != 0) { if (rv != 0) {
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_UPDATE, RUN_STATE_ERR_CB(XBPS_STATE_UPDATE_FAIL,
pkgver, rv); pkgver, rv);
goto out; goto out;
} }
@ -270,20 +269,20 @@ xbps_transaction_commit(prop_dictionary_t transd)
/* /*
* Unpack binary package. * Unpack binary package.
*/ */
RUN_TRANS_CB(XBPS_TRANS_STATE_UNPACK, NULL, RUN_STATE_CB(XBPS_STATE_UNPACK, NULL,
pkgver, filen, NULL); pkgver, filen, NULL);
if ((rv = xbps_unpack_binary_pkg(obj)) != 0) { if ((rv = xbps_unpack_binary_pkg(obj)) != 0) {
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_UNPACK, RUN_STATE_ERR_CB(XBPS_STATE_UNPACK_FAIL,
pkgver, rv); pkgver, rv);
goto out; goto out;
} }
/* /*
* Register package. * Register package.
*/ */
RUN_TRANS_CB(XBPS_TRANS_STATE_REGISTER, RUN_STATE_CB(XBPS_STATE_REGISTER,
NULL, pkgver, filen, NULL); NULL, pkgver, filen, NULL);
if ((rv = xbps_register_pkg(obj)) != 0) { if ((rv = xbps_register_pkg(obj)) != 0) {
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_REGISTER, RUN_STATE_ERR_CB(XBPS_STATE_REGISTER_FAIL,
pkgver, rv); pkgver, rv);
goto out; goto out;
} }
@ -293,7 +292,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
/* /*
* Configure all unpacked packages. * Configure all unpacked packages.
*/ */
RUN_TRANS_CB(XBPS_TRANS_STATE_CONFIGURE, RUN_STATE_CB(XBPS_STATE_CONFIGURE,
"[*] Configuring unpacked packages", NULL, NULL, NULL); "[*] Configuring unpacked packages", NULL, NULL, NULL);
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
@ -309,8 +308,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
if ((rv = xbps_configure_pkg(pkgname, version, if ((rv = xbps_configure_pkg(pkgname, version,
false, update)) != 0) { false, update)) != 0) {
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_CONFIGURE, RUN_STATE_ERR_CB(XBPS_STATE_CONFIGURE_FAIL, pkgver, rv);
pkgver, rv);
goto out; goto out;
} }
} }