libxbps: revamped trans states/cb to be more generic, not just for transactions.
This commit is contained in:
parent
dc4f7af890
commit
86f1f18571
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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));
|
||||
}
|
@ -4,7 +4,7 @@ TOPDIR = ../..
|
||||
BIN = xbps-repo
|
||||
OBJS = main.o index.o show.o find-files.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
|
||||
|
||||
include $(TOPDIR)/bin/prog.mk
|
||||
|
@ -138,8 +138,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 (rootdir)
|
||||
|
@ -55,7 +55,7 @@
|
||||
*/
|
||||
#define XBPS_PKGINDEX_VERSION "1.3"
|
||||
|
||||
#define XBPS_API_VERSION "20111110"
|
||||
#define XBPS_API_VERSION "20111111"
|
||||
#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.
|
||||
*
|
||||
* <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.
|
||||
*/
|
||||
typedef enum trans_state {
|
||||
XBPS_TRANS_STATE_UNKNOWN = 0,
|
||||
XBPS_TRANS_STATE_DOWNLOAD,
|
||||
XBPS_TRANS_STATE_VERIFY,
|
||||
XBPS_TRANS_STATE_REMOVE,
|
||||
XBPS_TRANS_STATE_PURGE,
|
||||
XBPS_TRANS_STATE_REPLACE,
|
||||
XBPS_TRANS_STATE_INSTALL,
|
||||
XBPS_TRANS_STATE_UPDATE,
|
||||
XBPS_TRANS_STATE_UNPACK,
|
||||
XBPS_TRANS_STATE_CONFIGURE,
|
||||
XBPS_TRANS_STATE_REGISTER,
|
||||
XBPS_TRANS_STATE_REPOSYNC
|
||||
} trans_state_t;
|
||||
typedef enum xbps_state {
|
||||
XBPS_STATE_UNKNOWN = 0,
|
||||
XBPS_STATE_DOWNLOAD,
|
||||
XBPS_STATE_VERIFY,
|
||||
XBPS_STATE_REMOVE,
|
||||
XBPS_STATE_PURGE,
|
||||
XBPS_STATE_REPLACE,
|
||||
XBPS_STATE_INSTALL,
|
||||
XBPS_STATE_UPDATE,
|
||||
XBPS_STATE_UNPACK,
|
||||
XBPS_STATE_CONFIGURE,
|
||||
XBPS_STATE_REGISTER,
|
||||
XBPS_STATE_REPOSYNC,
|
||||
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"
|
||||
* @brief Structure to be passed as argument to the transaction
|
||||
* @struct xbps_cb_data xbps_api.h "xbps_api.h"
|
||||
* @brief Structure to be passed as argument to the state
|
||||
* function callbacks.
|
||||
*/
|
||||
struct xbps_transaction_cb_data {
|
||||
struct xbps_state_cb_data {
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* Transaction's string description (set internally, read-only).
|
||||
* XBPS state string description (set internally, read-only).
|
||||
*/
|
||||
const char *desc;
|
||||
/**
|
||||
* @var pkgver
|
||||
*
|
||||
* Transaction's current pkgname/version string
|
||||
* XBPS state current pkgname/version string
|
||||
* (set internally, read-only).
|
||||
*/
|
||||
const char *pkgver;
|
||||
@ -241,7 +250,7 @@ struct xbps_transaction_cb_data {
|
||||
/**
|
||||
* @var err
|
||||
*
|
||||
* Transaction error value (set internally, read-only).
|
||||
* XBPS state error value (set internally, read-only).
|
||||
*/
|
||||
int err;
|
||||
/**
|
||||
@ -404,27 +413,19 @@ struct xbps_handle {
|
||||
*/
|
||||
prop_dictionary_t regpkgdb_dictionary;
|
||||
/**
|
||||
* @var xbps_transaction_cb
|
||||
* @var xbps_state_cb
|
||||
*
|
||||
* 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
|
||||
* a transaction when an error happens.
|
||||
* Pointer to a xbps_state_cb_data structure. It's allocated by
|
||||
* xbps_handle_alloc(), set internally.
|
||||
*/
|
||||
void (*xbps_transaction_err_cb)(struct xbps_transaction_cb_data *);
|
||||
/**
|
||||
* @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;
|
||||
struct xbps_state_cb_data *xscd;
|
||||
/**
|
||||
* @var xbps_unpack_cb
|
||||
*
|
||||
|
@ -207,8 +207,8 @@ xbps_end(struct xbps_handle *xh)
|
||||
free(xh->xfcd);
|
||||
if (xh->xucd != NULL)
|
||||
free(xh->xucd);
|
||||
if (xh->xtcd != NULL)
|
||||
free(xh->xtcd);
|
||||
if (xh->xscd != NULL)
|
||||
free(xh->xscd);
|
||||
|
||||
free(xh);
|
||||
xh = NULL;
|
||||
@ -227,24 +227,24 @@ xbps_handle_alloc(void)
|
||||
{
|
||||
struct xbps_handle *xh;
|
||||
|
||||
xh = calloc(1, sizeof(struct xbps_handle));
|
||||
xh = malloc(sizeof *xh);
|
||||
if (xh == NULL)
|
||||
return NULL;
|
||||
xh->xtcd = calloc(1, sizeof(struct xbps_transaction_cb_data));
|
||||
if (xh->xtcd == NULL) {
|
||||
xh->xscd = malloc(sizeof *xh->xscd);
|
||||
if (xh->xscd == NULL) {
|
||||
free(xh);
|
||||
return NULL;
|
||||
}
|
||||
xh->xucd = calloc(1, sizeof(struct xbps_unpack_cb_data));
|
||||
xh->xucd = malloc(sizeof *xh->xucd);
|
||||
if (xh->xucd == NULL) {
|
||||
free(xh->xtcd);
|
||||
free(xh->xscd);
|
||||
free(xh);
|
||||
return NULL;
|
||||
}
|
||||
xh->xfcd = calloc(1, sizeof(struct xbps_fetch_cb_data));
|
||||
xh->xfcd = malloc(sizeof *xh->xfcd);
|
||||
if (xh->xfcd == NULL) {
|
||||
free(xh->xucd);
|
||||
free(xh->xtcd);
|
||||
free(xh->xscd);
|
||||
free(xh);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -120,13 +120,14 @@ xbps_configure_pkg(const char *pkgname,
|
||||
if (pkgver == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
if (xhp->xbps_transaction_cb) {
|
||||
xhp->xtcd->desc = NULL;
|
||||
xhp->xtcd->binpkg_fname = NULL;
|
||||
xhp->xtcd->repourl = NULL;
|
||||
xhp->xtcd->state = XBPS_TRANS_STATE_CONFIGURE;
|
||||
xhp->xtcd->pkgver = pkgver;
|
||||
xhp->xbps_transaction_cb(xhp->xtcd);
|
||||
if (xhp->xbps_state_cb) {
|
||||
xhp->xscd->desc = NULL;
|
||||
xhp->xscd->binpkg_fname = NULL;
|
||||
xhp->xscd->repourl = NULL;
|
||||
xhp->xscd->err = 0;
|
||||
xhp->xscd->state = XBPS_STATE_CONFIGURE;
|
||||
xhp->xscd->pkgver = pkgver;
|
||||
xhp->xbps_state_cb(xhp->xscd);
|
||||
}
|
||||
|
||||
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
|
||||
@ -166,5 +167,12 @@ xbps_configure_pkg(const char *pkgname,
|
||||
XBPS_PKG_STATE_INSTALLED);
|
||||
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;
|
||||
}
|
||||
|
@ -166,24 +166,24 @@ xbps_repository_sync_pkg_index(const char *uri)
|
||||
fetch_outputdir = metadir;
|
||||
|
||||
/* reposync start cb */
|
||||
if (xhp->xbps_transaction_cb) {
|
||||
xhp->xtcd->state = XBPS_TRANS_STATE_REPOSYNC;
|
||||
xhp->xtcd->repourl = uri;
|
||||
xhp->xbps_transaction_cb(xhp->xtcd);
|
||||
if (xhp->xbps_state_cb) {
|
||||
xhp->xscd->state = XBPS_STATE_REPOSYNC;
|
||||
xhp->xscd->repourl = uri;
|
||||
xhp->xbps_state_cb(xhp->xscd);
|
||||
}
|
||||
/*
|
||||
* Download index.plist file from repository.
|
||||
*/
|
||||
if (xbps_fetch_file(rpidx, fetch_outputdir, true, NULL) == -1) {
|
||||
/* reposync error cb */
|
||||
if (xhp->xbps_transaction_err_cb) {
|
||||
xhp->xtcd->state = XBPS_TRANS_STATE_REPOSYNC;
|
||||
xhp->xtcd->repourl = uri;
|
||||
if (xhp->xbps_state_cb) {
|
||||
xhp->xscd->state = XBPS_STATE_REPOSYNC_FAIL;
|
||||
xhp->xscd->repourl = uri;
|
||||
if (fetchLastErrCode != 0)
|
||||
xhp->xtcd->err = fetchLastErrCode;
|
||||
xhp->xscd->err = fetchLastErrCode;
|
||||
else
|
||||
xhp->xtcd->err = errno;
|
||||
xhp->xbps_transaction_err_cb(xhp->xtcd);
|
||||
xhp->xscd->err = errno;
|
||||
xhp->xbps_state_cb(xhp->xscd);
|
||||
}
|
||||
rv = -1;
|
||||
goto out;
|
||||
|
@ -35,33 +35,33 @@
|
||||
|
||||
#include "xbps_api_impl.h"
|
||||
|
||||
#define RUN_TRANS_CB(s, d, p, bf, burl) \
|
||||
#define RUN_STATE_CB(s, d, p, bf, burl) \
|
||||
do { \
|
||||
if (xhp->xbps_transaction_cb != NULL) { \
|
||||
xhp->xtcd->state = s; \
|
||||
xhp->xtcd->desc = d; \
|
||||
xhp->xtcd->pkgver = p; \
|
||||
xhp->xtcd->binpkg_fname = bf; \
|
||||
xhp->xtcd->repourl = burl; \
|
||||
(*xhp->xbps_transaction_cb)(xhp->xtcd); \
|
||||
if (xhp->xbps_state_cb != NULL) { \
|
||||
xhp->xscd->state = s; \
|
||||
xhp->xscd->desc = d; \
|
||||
xhp->xscd->pkgver = p; \
|
||||
xhp->xscd->binpkg_fname = bf; \
|
||||
xhp->xscd->repourl = burl; \
|
||||
(*xhp->xbps_state_cb)(xhp->xscd); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RUN_TRANS_ERR_CB(s, p, r) \
|
||||
do { \
|
||||
if (xhp->xbps_transaction_err_cb != NULL) { \
|
||||
xhp->xtcd->state = s; \
|
||||
xhp->xtcd->pkgver = p; \
|
||||
xhp->xtcd->err = r; \
|
||||
(*xhp->xbps_transaction_err_cb)(xhp->xtcd); \
|
||||
} \
|
||||
#define RUN_STATE_ERR_CB(s, p, r) \
|
||||
do { \
|
||||
if (xhp->xbps_state_cb != NULL) { \
|
||||
xhp->xscd->state = s; \
|
||||
xhp->xscd->pkgver = p; \
|
||||
xhp->xscd->err = r; \
|
||||
(*xhp->xbps_state_cb)(xhp->xscd); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int
|
||||
check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
{
|
||||
prop_object_t obj;
|
||||
const char *pkgver, *repoloc, *filename, *sha256, *trans;
|
||||
const char *pkgver, *repoloc, *filen, *sha256, *trans;
|
||||
char *binfile;
|
||||
int rv = 0;
|
||||
|
||||
@ -75,8 +75,8 @@ check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
assert(repoloc != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
assert(pkgver != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
||||
assert(filename != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
|
||||
assert(filen != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"filename-sha256", &sha256);
|
||||
assert(sha256 != NULL);
|
||||
@ -86,12 +86,11 @@ check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_VERIFY,
|
||||
NULL, pkgver, filename, repoloc);
|
||||
RUN_STATE_CB(XBPS_STATE_VERIFY, NULL, pkgver, filen, repoloc);
|
||||
rv = xbps_file_hash_check(binfile, sha256);
|
||||
if (rv != 0) {
|
||||
free(binfile);
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_VERIFY, pkgver, rv);
|
||||
RUN_STATE_ERR_CB(XBPS_STATE_VERIFY_FAIL, pkgver, rv);
|
||||
break;
|
||||
}
|
||||
free(binfile);
|
||||
@ -105,7 +104,7 @@ static int
|
||||
download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
{
|
||||
prop_object_t obj;
|
||||
const char *pkgver, *repoloc, *filename, *trans;
|
||||
const char *pkgver, *repoloc, *filen, *trans;
|
||||
char *binfile;
|
||||
int rv = 0;
|
||||
|
||||
@ -119,8 +118,8 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
assert(repoloc != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
assert(pkgver != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
||||
assert(filename != NULL);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
|
||||
assert(filen != NULL);
|
||||
|
||||
binfile = xbps_path_from_repository_uri(obj, repoloc);
|
||||
if (binfile == NULL) {
|
||||
@ -147,15 +146,15 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_DOWNLOAD,
|
||||
NULL, pkgver, filename, repoloc);
|
||||
RUN_STATE_CB(XBPS_STATE_DOWNLOAD, NULL, pkgver, filen, repoloc);
|
||||
/*
|
||||
* Fetch binary package.
|
||||
*/
|
||||
rv = xbps_fetch_file(binfile,
|
||||
prop_string_cstring_nocopy(xhp->cachedir), false, NULL);
|
||||
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);
|
||||
break;
|
||||
}
|
||||
@ -186,14 +185,14 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
/*
|
||||
* 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);
|
||||
if ((rv = download_binpkgs(xhp, iter)) != 0)
|
||||
goto out;
|
||||
/*
|
||||
* 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);
|
||||
if ((rv = check_binpkgs_hash(xhp, iter)) != 0)
|
||||
goto out;
|
||||
@ -201,7 +200,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
* Install, update, configure or remove packages as specified
|
||||
* in the transaction dictionary.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_INSTALL,
|
||||
RUN_STATE_CB(XBPS_STATE_INSTALL,
|
||||
"[*] Running transaction tasks", NULL, NULL, 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",
|
||||
&update);
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_REMOVE,
|
||||
RUN_STATE_CB(XBPS_STATE_REMOVE,
|
||||
NULL, pkgver, NULL, NULL);
|
||||
rv = xbps_remove_pkg(pkgname, version, update);
|
||||
if (rv != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_REMOVE,
|
||||
RUN_STATE_ERR_CB(XBPS_STATE_REMOVE_FAIL,
|
||||
pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
if (update)
|
||||
continue;
|
||||
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_PURGE,
|
||||
RUN_STATE_CB(XBPS_STATE_PURGE,
|
||||
NULL, pkgver, NULL, NULL);
|
||||
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);
|
||||
goto out;
|
||||
}
|
||||
@ -242,7 +241,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
*/
|
||||
rv = xbps_configure_pkg(pkgname, version, false, false);
|
||||
if (rv != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_CONFIGURE,
|
||||
RUN_STATE_ERR_CB(XBPS_STATE_CONFIGURE_FAIL,
|
||||
pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
@ -258,11 +257,11 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
* Update a package: execute pre-remove
|
||||
* action if found before unpacking.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_UPDATE,
|
||||
RUN_STATE_CB(XBPS_STATE_UPDATE,
|
||||
NULL, pkgver, filen, NULL);
|
||||
rv = xbps_remove_pkg(pkgname, version, true);
|
||||
if (rv != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_UPDATE,
|
||||
RUN_STATE_ERR_CB(XBPS_STATE_UPDATE_FAIL,
|
||||
pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
@ -270,20 +269,20 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
/*
|
||||
* Unpack binary package.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_UNPACK, NULL,
|
||||
RUN_STATE_CB(XBPS_STATE_UNPACK, NULL,
|
||||
pkgver, filen, NULL);
|
||||
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);
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Register package.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_REGISTER,
|
||||
RUN_STATE_CB(XBPS_STATE_REGISTER,
|
||||
NULL, pkgver, filen, NULL);
|
||||
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);
|
||||
goto out;
|
||||
}
|
||||
@ -293,7 +292,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
/*
|
||||
* Configure all unpacked packages.
|
||||
*/
|
||||
RUN_TRANS_CB(XBPS_TRANS_STATE_CONFIGURE,
|
||||
RUN_STATE_CB(XBPS_STATE_CONFIGURE,
|
||||
"[*] Configuring unpacked packages", NULL, NULL, 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,
|
||||
false, update)) != 0) {
|
||||
RUN_TRANS_ERR_CB(XBPS_TRANS_STATE_CONFIGURE,
|
||||
pkgver, rv);
|
||||
RUN_STATE_ERR_CB(XBPS_STATE_CONFIGURE_FAIL, pkgver, rv);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user