Require handle argument to all alpm_trans_*() methods

Begin enforcing the need to pass a handle. This allows us to remove one
more extern handle declaration from the backend.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-06-07 13:29:05 -05:00
parent 17a6ac5675
commit 24000b83c9
8 changed files with 50 additions and 45 deletions

View file

@ -794,54 +794,62 @@ typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, size_t, size_t); typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, size_t, size_t);
/** Returns the bitfield of flags for the current transaction. /** Returns the bitfield of flags for the current transaction.
* @sa _pmtransflag_t * @param handle the context handle
* @return the bitfield of transaction flags
*/ */
int alpm_trans_get_flags(void); pmtransflag_t alpm_trans_get_flags(pmhandle_t *handle);
/** Returns a list of packages added by the transaction. /** Returns a list of packages added by the transaction.
* @param handle the context handle
* @return a list of pmpkg_t structures * @return a list of pmpkg_t structures
*/ */
alpm_list_t * alpm_trans_get_add(void); alpm_list_t * alpm_trans_get_add(pmhandle_t *handle);
/** Returns the list of packages removed by the transaction. /** Returns the list of packages removed by the transaction.
* @param handle the context handle
* @return a list of pmpkg_t structures * @return a list of pmpkg_t structures
*/ */
alpm_list_t * alpm_trans_get_remove(void); alpm_list_t * alpm_trans_get_remove(pmhandle_t *handle);
/** Initialize the transaction. /** Initialize the transaction.
* @param handle the context handle
* @param flags flags of the transaction (like nodeps, etc) * @param flags flags of the transaction (like nodeps, etc)
* @param event event callback function pointer * @param event event callback function pointer
* @param conv question callback function pointer * @param conv question callback function pointer
* @param progress progress callback function pointer * @param progress progress callback function pointer
* @return 0 on success, -1 on error (pm_errno is set accordingly) * @return 0 on success, -1 on error (pm_errno is set accordingly)
*/ */
int alpm_trans_init(pmtransflag_t flags, int alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags,
alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv, alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress cb_progress); alpm_trans_cb_progress cb_progress);
/** Prepare a transaction. /** Prepare a transaction.
* @param handle the context handle
* @param data the address of an alpm_list where a list * @param data the address of an alpm_list where a list
* of pmdepmissing_t objects is dumped (conflicting packages) * of pmdepmissing_t objects is dumped (conflicting packages)
* @return 0 on success, -1 on error (pm_errno is set accordingly) * @return 0 on success, -1 on error (pm_errno is set accordingly)
*/ */
int alpm_trans_prepare(alpm_list_t **data); int alpm_trans_prepare(pmhandle_t *handle, alpm_list_t **data);
/** Commit a transaction. /** Commit a transaction.
* @param handle the context handle
* @param data the address of an alpm_list where detailed description * @param data the address of an alpm_list where detailed description
* of an error can be dumped (ie. list of conflicting files) * of an error can be dumped (ie. list of conflicting files)
* @return 0 on success, -1 on error (pm_errno is set accordingly) * @return 0 on success, -1 on error (pm_errno is set accordingly)
*/ */
int alpm_trans_commit(alpm_list_t **data); int alpm_trans_commit(pmhandle_t *handle, alpm_list_t **data);
/** Interrupt a transaction. /** Interrupt a transaction.
* @param handle the context handle
* @return 0 on success, -1 on error (pm_errno is set accordingly) * @return 0 on success, -1 on error (pm_errno is set accordingly)
*/ */
int alpm_trans_interrupt(void); int alpm_trans_interrupt(pmhandle_t *handle);
/** Release a transaction. /** Release a transaction.
* @param handle the context handle
* @return 0 on success, -1 on error (pm_errno is set accordingly) * @return 0 on success, -1 on error (pm_errno is set accordingly)
*/ */
int alpm_trans_release(void); int alpm_trans_release(pmhandle_t *handle);
/** @} */ /** @} */
/** @name Common Transactions */ /** @name Common Transactions */

View file

@ -204,9 +204,9 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
return newtargs; return newtargs;
} }
static int no_dep_version(void) static int no_dep_version(pmhandle_t *handle)
{ {
int flags = alpm_trans_get_flags(); int flags = alpm_trans_get_flags(handle);
return flags != -1 && (flags & PM_TRANS_FLAG_NODEPVERSION); return flags != -1 && (flags & PM_TRANS_FLAG_NODEPVERSION);
} }
@ -282,7 +282,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
} }
alpm_list_free(targets); alpm_list_free(targets);
nodepversion = no_dep_version(); nodepversion = no_dep_version(handle);
/* look for unsatisfied dependencies of the upgrade list */ /* look for unsatisfied dependencies of the upgrade list */
for(i = upgrade; i; i = i->next) { for(i = upgrade; i; i = i->next) {

View file

@ -43,9 +43,6 @@
#include "sync.h" #include "sync.h"
#include "alpm.h" #include "alpm.h"
/* global handle variable */
extern pmhandle_t *handle;
/** \addtogroup alpm_trans Transaction Functions /** \addtogroup alpm_trans Transaction Functions
* @brief Functions to manipulate libalpm transactions * @brief Functions to manipulate libalpm transactions
* @{ * @{
@ -99,7 +96,7 @@ static int remove_lock(pmhandle_t *handle)
} }
/** Initialize the transaction. */ /** Initialize the transaction. */
int SYMEXPORT alpm_trans_init(pmtransflag_t flags, int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv, alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress) alpm_trans_cb_progress progress)
{ {
@ -144,7 +141,7 @@ int SYMEXPORT alpm_trans_init(pmtransflag_t flags,
return 0; return 0;
} }
static alpm_list_t *check_arch(alpm_list_t *pkgs) static alpm_list_t *check_arch(pmhandle_t *handle, alpm_list_t *pkgs)
{ {
alpm_list_t *i; alpm_list_t *i;
alpm_list_t *invalid = NULL; alpm_list_t *invalid = NULL;
@ -170,7 +167,7 @@ static alpm_list_t *check_arch(alpm_list_t *pkgs)
} }
/** Prepare a transaction. */ /** Prepare a transaction. */
int SYMEXPORT alpm_trans_prepare(alpm_list_t **data) int SYMEXPORT alpm_trans_prepare(pmhandle_t *handle, alpm_list_t **data)
{ {
pmtrans_t *trans; pmtrans_t *trans;
@ -188,7 +185,7 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
return 0; return 0;
} }
alpm_list_t *invalid = check_arch(trans->add); alpm_list_t *invalid = check_arch(handle, trans->add);
if(invalid) { if(invalid) {
if(data) { if(data) {
*data = invalid; *data = invalid;
@ -214,7 +211,7 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
} }
/** Commit a transaction. */ /** Commit a transaction. */
int SYMEXPORT alpm_trans_commit(alpm_list_t **data) int SYMEXPORT alpm_trans_commit(pmhandle_t *handle, alpm_list_t **data)
{ {
pmtrans_t *trans; pmtrans_t *trans;
@ -253,7 +250,7 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
} }
/** Interrupt a transaction. */ /** Interrupt a transaction. */
int SYMEXPORT alpm_trans_interrupt(void) int SYMEXPORT alpm_trans_interrupt(pmhandle_t *handle)
{ {
pmtrans_t *trans; pmtrans_t *trans;
@ -271,7 +268,7 @@ int SYMEXPORT alpm_trans_interrupt(void)
} }
/** Release a transaction. */ /** Release a transaction. */
int SYMEXPORT alpm_trans_release(void) int SYMEXPORT alpm_trans_release(pmhandle_t *handle)
{ {
pmtrans_t *trans; pmtrans_t *trans;
@ -428,7 +425,7 @@ cleanup:
return retval; return retval;
} }
int SYMEXPORT alpm_trans_get_flags() pmtransflag_t SYMEXPORT alpm_trans_get_flags(pmhandle_t *handle)
{ {
/* Sanity checks */ /* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
@ -437,7 +434,7 @@ int SYMEXPORT alpm_trans_get_flags()
return handle->trans->flags; return handle->trans->flags;
} }
alpm_list_t SYMEXPORT * alpm_trans_get_add() alpm_list_t SYMEXPORT *alpm_trans_get_add(pmhandle_t *handle)
{ {
/* Sanity checks */ /* Sanity checks */
ASSERT(handle != NULL, return NULL); ASSERT(handle != NULL, return NULL);
@ -446,7 +443,7 @@ alpm_list_t SYMEXPORT * alpm_trans_get_add()
return handle->trans->add; return handle->trans->add;
} }
alpm_list_t SYMEXPORT * alpm_trans_get_remove() alpm_list_t SYMEXPORT *alpm_trans_get_remove(pmhandle_t *handle)
{ {
/* Sanity checks */ /* Sanity checks */
ASSERT(handle != NULL, return NULL); ASSERT(handle != NULL, return NULL);

View file

@ -307,12 +307,12 @@ static void handler(int signum)
} else if(signum == SIGINT) { } else if(signum == SIGINT) {
const char *msg = "\nInterrupt signal received\n"; const char *msg = "\nInterrupt signal received\n";
xwrite(err, msg, strlen(msg)); xwrite(err, msg, strlen(msg));
if(alpm_trans_interrupt() == 0) { if(alpm_trans_interrupt(config->handle) == 0) {
/* a transaction is being interrupted, don't exit pacman yet. */ /* a transaction is being interrupted, don't exit pacman yet. */
return; return;
} }
/* no commiting transaction, we can release it now and then exit pacman */ /* no commiting transaction, we can release it now and then exit pacman */
alpm_trans_release(); alpm_trans_release(config->handle);
/* output a newline to be sure we clear any line we may be on */ /* output a newline to be sure we clear any line we may be on */
xwrite(out, "\n", 1); xwrite(out, "\n", 1);
} }

View file

@ -99,7 +99,7 @@ int pacman_remove(alpm_list_t *targets)
} }
/* Step 2: prepare the transaction based on its type, targets and flags */ /* Step 2: prepare the transaction based on its type, targets and flags */
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(config->handle, &data) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
switch(pm_errno) { switch(pm_errno) {
@ -129,7 +129,7 @@ int pacman_remove(alpm_list_t *targets)
/* Search for holdpkg in target list */ /* Search for holdpkg in target list */
int holdpkg = 0; int holdpkg = 0;
for(i = alpm_trans_get_remove(); i; i = alpm_list_next(i)) { for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i); pmpkg_t *pkg = alpm_list_getdata(i);
if(alpm_list_find_str(config->holdpkg, alpm_pkg_get_name(pkg))) { if(alpm_list_find_str(config->holdpkg, alpm_pkg_get_name(pkg))) {
pm_printf(PM_LOG_WARNING, _("%s is designated as a HoldPkg.\n"), pm_printf(PM_LOG_WARNING, _("%s is designated as a HoldPkg.\n"),
@ -143,7 +143,7 @@ int pacman_remove(alpm_list_t *targets)
} }
/* Step 3: actually perform the removal */ /* Step 3: actually perform the removal */
alpm_list_t *pkglist = alpm_trans_get_remove(); alpm_list_t *pkglist = alpm_trans_get_remove(config->handle);
if(pkglist == NULL) { if(pkglist == NULL) {
printf(_(" there is nothing to do\n")); printf(_(" there is nothing to do\n"));
goto cleanup; /* we are done */ goto cleanup; /* we are done */
@ -162,7 +162,7 @@ int pacman_remove(alpm_list_t *targets)
goto cleanup; goto cleanup;
} }
if(alpm_trans_commit(NULL) == -1) { if(alpm_trans_commit(config->handle, NULL) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
retval = 1; retval = 1;

View file

@ -768,7 +768,7 @@ static int sync_trans(alpm_list_t *targets)
} }
/* Step 2: "compute" the transaction based on targets and flags */ /* Step 2: "compute" the transaction based on targets and flags */
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(config->handle, &data) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
switch(pm_errno) { switch(pm_errno) {
@ -810,7 +810,7 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup; goto cleanup;
} }
packages = alpm_trans_get_add(); packages = alpm_trans_get_add(config->handle);
if(packages == NULL) { if(packages == NULL) {
/* nothing to do: just exit without complaining */ /* nothing to do: just exit without complaining */
printf(_(" there is nothing to do\n")); printf(_(" there is nothing to do\n"));
@ -823,8 +823,8 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup; goto cleanup;
} }
display_targets(alpm_trans_get_remove(), 0); display_targets(alpm_trans_get_remove(config->handle), 0);
display_targets(alpm_trans_get_add(), 1); display_targets(alpm_trans_get_add(config->handle), 1);
printf("\n"); printf("\n");
int confirm; int confirm;
@ -837,7 +837,7 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup; goto cleanup;
} }
if(alpm_trans_commit(&data) == -1) { if(alpm_trans_commit(config->handle, &data) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
switch(pm_errno) { switch(pm_errno) {

View file

@ -93,7 +93,7 @@ int pacman_upgrade(alpm_list_t *targets)
/* Step 2: "compute" the transaction based on targets and flags */ /* Step 2: "compute" the transaction based on targets and flags */
/* TODO: No, compute nothing. This is stupid. */ /* TODO: No, compute nothing. This is stupid. */
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(config->handle, &data) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
switch(pm_errno) { switch(pm_errno) {
@ -142,20 +142,20 @@ int pacman_upgrade(alpm_list_t *targets)
/* Step 3: perform the installation */ /* Step 3: perform the installation */
if(config->print) { if(config->print) {
print_packages(alpm_trans_get_add()); print_packages(alpm_trans_get_add(config->handle));
trans_release(); trans_release();
return 0; return 0;
} }
/* print targets and ask user confirmation */ /* print targets and ask user confirmation */
alpm_list_t *packages = alpm_trans_get_add(); alpm_list_t *packages = alpm_trans_get_add(config->handle);
if(packages == NULL) { /* we are done */ if(packages == NULL) { /* we are done */
printf(_(" there is nothing to do\n")); printf(_(" there is nothing to do\n"));
trans_release(); trans_release();
return retval; return retval;
} }
display_targets(alpm_trans_get_remove(), 0); display_targets(alpm_trans_get_remove(config->handle), 0);
display_targets(alpm_trans_get_add(), 1); display_targets(alpm_trans_get_add(config->handle), 1);
printf("\n"); printf("\n");
int confirm = yesno(_("Proceed with installation?")); int confirm = yesno(_("Proceed with installation?"));
if(!confirm) { if(!confirm) {
@ -163,7 +163,7 @@ int pacman_upgrade(alpm_list_t *targets)
return retval; return retval;
} }
if(alpm_trans_commit(&data) == -1) { if(alpm_trans_commit(config->handle, &data) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
switch(pm_errno) { switch(pm_errno) {

View file

@ -53,9 +53,9 @@ int trans_init(pmtransflag_t flags)
{ {
int ret; int ret;
if(config->print) { if(config->print) {
ret = alpm_trans_init(flags, NULL, NULL, NULL); ret = alpm_trans_init(config->handle, flags, NULL, NULL, NULL);
} else { } else {
ret = alpm_trans_init(flags, cb_trans_evt, cb_trans_conv, ret = alpm_trans_init(config->handle, flags, cb_trans_evt, cb_trans_conv,
cb_trans_progress); cb_trans_progress);
} }
@ -78,7 +78,7 @@ int trans_init(pmtransflag_t flags)
int trans_release(void) int trans_release(void)
{ {
if(alpm_trans_release() == -1) { if(alpm_trans_release(config->handle) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
return -1; return -1;