1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

Move all callbacks up to the handle level

This was just disgusting before, unnecessary to limit these to only
usage in a transaction. Still a lot of more room for cleanup but we'll
start by attaching them to the handle rather than the transaction we may
or may not even want to use these callbacks.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-09-01 17:16:56 -05:00
parent d88e524e7c
commit 37da18aee8
16 changed files with 161 additions and 117 deletions

7
README
View File

@ -395,6 +395,8 @@ API CHANGES BETWEEN 3.5 AND 4.0
- alpm_pkg_load() now requires an extra parameter of an alpm_siglevel_t - alpm_pkg_load() now requires an extra parameter of an alpm_siglevel_t
- alpm_db_setserver() replaced by alpm_db_set_servers(), alpm_db_add_server(), - alpm_db_setserver() replaced by alpm_db_set_servers(), alpm_db_add_server(),
alpm_db_remove_server() alpm_db_remove_server()
- alpm_trans_init() no longer takes callbacks, set those using
alpm_option_set_*cb() functions
- many functions now require a first parameter of an alpm_handle_t *: - many functions now require a first parameter of an alpm_handle_t *:
- alpm_option_get_* - alpm_option_get_*
- alpm_option_set_* - alpm_option_set_*
@ -425,10 +427,13 @@ API CHANGES BETWEEN 3.5 AND 4.0
- alpm_pkg_reason_t - alpm_pkg_reason_t
[ADDED] [ADDED]
- option functions:
alpm_{get,set}_eventcb(), alpm_option_{get,set}_convcb(),
alpm_option_{get,set}_progresscb()
- package signing functions: - package signing functions:
alpm_option_get_default_siglevel(), alpm_option_set_default_siglevel(), alpm_option_get_default_siglevel(), alpm_option_set_default_siglevel(),
alpm_option_get_gpgdir(), alpm_option_set_gpgdir(), alpm_db_get_siglevel(), alpm_option_get_gpgdir(), alpm_option_set_gpgdir(), alpm_db_get_siglevel(),
alpm_sigresult_cleanup(), alpm_db_check_pgp_signature(), alpm_pkg_check_pgp_signature(), alpm_siglist_cleanup(), alpm_db_check_pgp_signature(), alpm_pkg_check_pgp_signature(),
alpm_pkg_get_origin(), alpm_pkg_get_sha256sum(), alpm_pkg_get_base64_sig() alpm_pkg_get_origin(), alpm_pkg_get_sha256sum(), alpm_pkg_get_base64_sig()
- list functions: - list functions:
alpm_list_to_array(), alpm_list_previous() alpm_list_to_array(), alpm_list_previous()

View File

@ -473,7 +473,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
goto cleanup; goto cleanup;
} }
EVENT(trans, ALPM_TRANS_EVT_UPGRADE_START, newpkg, local); EVENT(handle, ALPM_TRANS_EVT_UPGRADE_START, newpkg, local);
_alpm_log(handle, ALPM_LOG_DEBUG, "upgrading package %s-%s\n", _alpm_log(handle, ALPM_LOG_DEBUG, "upgrading package %s-%s\n",
newpkg->name, newpkg->version); newpkg->name, newpkg->version);
@ -488,7 +488,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
} else { } else {
is_upgrade = 0; is_upgrade = 0;
EVENT(trans, ALPM_TRANS_EVT_ADD_START, newpkg, NULL); EVENT(handle, ALPM_TRANS_EVT_ADD_START, newpkg, NULL);
_alpm_log(handle, ALPM_LOG_DEBUG, "adding package %s-%s\n", _alpm_log(handle, ALPM_LOG_DEBUG, "adding package %s-%s\n",
newpkg->name, newpkg->version); newpkg->name, newpkg->version);
@ -567,10 +567,10 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
/* call PROGRESS once with 0 percent, as we sort-of skip that here */ /* call PROGRESS once with 0 percent, as we sort-of skip that here */
if(is_upgrade) { if(is_upgrade) {
PROGRESS(trans, ALPM_TRANS_PROGRESS_UPGRADE_START, PROGRESS(handle, ALPM_TRANS_PROGRESS_UPGRADE_START,
newpkg->name, 0, pkg_count, pkg_current); newpkg->name, 0, pkg_count, pkg_current);
} else { } else {
PROGRESS(trans, ALPM_TRANS_PROGRESS_ADD_START, PROGRESS(handle, ALPM_TRANS_PROGRESS_ADD_START,
newpkg->name, 0, pkg_count, pkg_current); newpkg->name, 0, pkg_count, pkg_current);
} }
@ -594,10 +594,10 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
} }
if(is_upgrade) { if(is_upgrade) {
PROGRESS(trans, ALPM_TRANS_PROGRESS_UPGRADE_START, PROGRESS(handle, ALPM_TRANS_PROGRESS_UPGRADE_START,
newpkg->name, percent, pkg_count, pkg_current); newpkg->name, percent, pkg_count, pkg_current);
} else { } else {
PROGRESS(trans, ALPM_TRANS_PROGRESS_ADD_START, PROGRESS(handle, ALPM_TRANS_PROGRESS_ADD_START,
newpkg->name, percent, pkg_count, pkg_current); newpkg->name, percent, pkg_count, pkg_current);
} }
@ -649,10 +649,10 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
} }
if(is_upgrade) { if(is_upgrade) {
PROGRESS(trans, ALPM_TRANS_PROGRESS_UPGRADE_START, PROGRESS(handle, ALPM_TRANS_PROGRESS_UPGRADE_START,
newpkg->name, 100, pkg_count, pkg_current); newpkg->name, 100, pkg_count, pkg_current);
} else { } else {
PROGRESS(trans, ALPM_TRANS_PROGRESS_ADD_START, PROGRESS(handle, ALPM_TRANS_PROGRESS_ADD_START,
newpkg->name, 100, pkg_count, pkg_current); newpkg->name, 100, pkg_count, pkg_current);
} }
@ -669,9 +669,9 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
} }
if(is_upgrade) { if(is_upgrade) {
EVENT(trans, ALPM_TRANS_EVT_UPGRADE_DONE, newpkg, oldpkg); EVENT(handle, ALPM_TRANS_EVT_UPGRADE_DONE, newpkg, oldpkg);
} else { } else {
EVENT(trans, ALPM_TRANS_EVT_ADD_DONE, newpkg, oldpkg); EVENT(handle, ALPM_TRANS_EVT_ADD_DONE, newpkg, oldpkg);
} }
cleanup: cleanup:

View File

@ -863,7 +863,7 @@ typedef enum _alpm_transflag_t {
ALPM_TRANS_FLAG_NOLOCK = (1 << 17) ALPM_TRANS_FLAG_NOLOCK = (1 << 17)
} alpm_transflag_t; } alpm_transflag_t;
/** Transaction events. /** Events.
* NULL parameters are passed to in all events unless specified otherwise. * NULL parameters are passed to in all events unless specified otherwise.
*/ */
typedef enum _alpm_transevt_t { typedef enum _alpm_transevt_t {
@ -943,7 +943,7 @@ typedef enum _alpm_transevt_t {
ALPM_TRANS_EVT_DISKSPACE_DONE, ALPM_TRANS_EVT_DISKSPACE_DONE,
} alpm_transevt_t; } alpm_transevt_t;
/** Transaction Conversations (ie, questions) */ /** Conversations (ie, questions) */
typedef enum _alpm_transconv_t { typedef enum _alpm_transconv_t {
ALPM_TRANS_CONV_INSTALL_IGNOREPKG = 1, ALPM_TRANS_CONV_INSTALL_IGNOREPKG = 1,
ALPM_TRANS_CONV_REPLACE_PKG = (1 << 1), ALPM_TRANS_CONV_REPLACE_PKG = (1 << 1),
@ -954,7 +954,7 @@ typedef enum _alpm_transconv_t {
ALPM_TRANS_CONV_SELECT_PROVIDER = (1 << 6), ALPM_TRANS_CONV_SELECT_PROVIDER = (1 << 6),
} alpm_transconv_t; } alpm_transconv_t;
/** Transaction Progress */ /** Progress */
typedef enum _alpm_transprog_t { typedef enum _alpm_transprog_t {
ALPM_TRANS_PROGRESS_ADD_START, ALPM_TRANS_PROGRESS_ADD_START,
ALPM_TRANS_PROGRESS_UPGRADE_START, ALPM_TRANS_PROGRESS_UPGRADE_START,
@ -964,15 +964,29 @@ typedef enum _alpm_transprog_t {
ALPM_TRANS_PROGRESS_INTEGRITY_START, ALPM_TRANS_PROGRESS_INTEGRITY_START,
} alpm_transprog_t; } alpm_transprog_t;
/** Transaction Event callback */ /** Event callback */
typedef void (*alpm_trans_cb_event)(alpm_transevt_t, void *, void *); typedef void (*alpm_cb_event)(alpm_transevt_t, void *, void *);
/** Transaction Conversation callback */ /** Conversation callback */
typedef void (*alpm_trans_cb_conv)(alpm_transconv_t, void *, void *, typedef void (*alpm_cb_conv)(alpm_transconv_t, void *, void *, void *, int *);
void *, int *);
/** Transaction Progress callback */ /** Progress callback */
typedef void (*alpm_trans_cb_progress)(alpm_transprog_t, const char *, int, size_t, size_t); typedef void (*alpm_cb_progress)(alpm_transprog_t, const char *, int, size_t, size_t);
/** Returns the callback used for events. */
alpm_cb_event alpm_option_get_eventcb(alpm_handle_t *handle);
/** Sets the callback used for events. */
int alpm_option_set_eventcb(alpm_handle_t *handle, alpm_cb_event cb);
/** Returns the callback used for conversations (questions). */
alpm_cb_conv alpm_option_get_convcb(alpm_handle_t *handle);
/** Sets the callback used for conversations (questions). */
int alpm_option_set_convcb(alpm_handle_t *handle, alpm_cb_conv cb);
/** Returns the callback used for operation progress. */
alpm_cb_progress alpm_option_get_progresscb(alpm_handle_t *handle);
/** Sets the callback used for operation progress. */
int alpm_option_set_progresscb(alpm_handle_t *handle, alpm_cb_progress cb);
/** Returns the bitfield of flags for the current transaction. /** Returns the bitfield of flags for the current transaction.
* @param handle the context handle * @param handle the context handle
@ -995,14 +1009,9 @@ alpm_list_t *alpm_trans_get_remove(alpm_handle_t *handle);
/** Initialize the transaction. /** Initialize the transaction.
* @param handle the context handle * @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 conv question 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(alpm_handle_t *handle, alpm_transflag_t flags, int alpm_trans_init(alpm_handle_t *handle, alpm_transflag_t flags);
alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress cb_progress);
/** Prepare a transaction. /** Prepare a transaction.
* @param handle the context handle * @param handle the context handle

View File

@ -384,7 +384,6 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
alpm_list_t *i, *conflicts = NULL; alpm_list_t *i, *conflicts = NULL;
size_t numtargs = alpm_list_count(upgrade); size_t numtargs = alpm_list_count(upgrade);
size_t current; size_t current;
alpm_trans_t *trans = handle->trans;
if(!upgrade) { if(!upgrade) {
return NULL; return NULL;
@ -402,7 +401,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
size_t filenum; size_t filenum;
int percent = (current * 100) / numtargs; int percent = (current * 100) / numtargs;
PROGRESS(trans, ALPM_TRANS_PROGRESS_CONFLICTS_START, "", percent, PROGRESS(handle, ALPM_TRANS_PROGRESS_CONFLICTS_START, "", percent,
numtargs, current); numtargs, current);
/* CHECK 1: check every target against every target */ /* CHECK 1: check every target against every target */
_alpm_log(handle, ALPM_LOG_DEBUG, "searching for file conflicts: %s\n", _alpm_log(handle, ALPM_LOG_DEBUG, "searching for file conflicts: %s\n",
@ -585,7 +584,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
free(tmpfiles.files); free(tmpfiles.files);
} }
} }
PROGRESS(trans, ALPM_TRANS_PROGRESS_CONFLICTS_START, "", 100, PROGRESS(handle, ALPM_TRANS_PROGRESS_CONFLICTS_START, "", 100,
numtargs, current); numtargs, current);
return conflicts; return conflicts;

View File

@ -582,7 +582,7 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
if(_alpm_pkg_should_ignore(handle, pkg)) { if(_alpm_pkg_should_ignore(handle, pkg)) {
int install = 0; int install = 0;
if(prompt) { if(prompt) {
QUESTION(handle->trans, ALPM_TRANS_CONV_INSTALL_IGNOREPKG, pkg, QUESTION(handle, ALPM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
NULL, NULL, &install); NULL, NULL, &install);
} else { } else {
_alpm_log(handle, ALPM_LOG_WARNING, _("ignoring package %s-%s\n"), _alpm_log(handle, ALPM_LOG_WARNING, _("ignoring package %s-%s\n"),
@ -607,7 +607,7 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
if(_alpm_pkg_should_ignore(handle, pkg)) { if(_alpm_pkg_should_ignore(handle, pkg)) {
int install = 0; int install = 0;
if(prompt) { if(prompt) {
QUESTION(handle->trans, ALPM_TRANS_CONV_INSTALL_IGNOREPKG, QUESTION(handle, ALPM_TRANS_CONV_INSTALL_IGNOREPKG,
pkg, NULL, NULL, &install); pkg, NULL, NULL, &install);
} else { } else {
_alpm_log(handle, ALPM_LOG_WARNING, _("ignoring package %s-%s\n"), _alpm_log(handle, ALPM_LOG_WARNING, _("ignoring package %s-%s\n"),
@ -640,7 +640,7 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
int index = 0; int index = 0;
if(count > 1) { if(count > 1) {
/* if there is more than one provider, we ask the user */ /* if there is more than one provider, we ask the user */
QUESTION(handle->trans, ALPM_TRANS_CONV_SELECT_PROVIDER, QUESTION(handle, ALPM_TRANS_CONV_SELECT_PROVIDER,
providers, dep, NULL, &index); providers, dep, NULL, &index);
} }
if(index >= 0 && index < count) { if(index >= 0 && index < count) {

View File

@ -260,7 +260,7 @@ int _alpm_check_diskspace(alpm_handle_t *handle)
for(targ = trans->remove; targ; targ = targ->next, current++) { for(targ = trans->remove; targ; targ = targ->next, current++) {
alpm_pkg_t *local_pkg; alpm_pkg_t *local_pkg;
int percent = (current * 100) / numtargs; int percent = (current * 100) / numtargs;
PROGRESS(trans, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", percent, PROGRESS(handle, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current); numtargs, current);
local_pkg = targ->data; local_pkg = targ->data;
@ -271,7 +271,7 @@ int _alpm_check_diskspace(alpm_handle_t *handle)
for(targ = trans->add; targ; targ = targ->next, current++) { for(targ = trans->add; targ; targ = targ->next, current++) {
alpm_pkg_t *pkg, *local_pkg; alpm_pkg_t *pkg, *local_pkg;
int percent = (current * 100) / numtargs; int percent = (current * 100) / numtargs;
PROGRESS(trans, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", percent, PROGRESS(handle, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current); numtargs, current);
pkg = targ->data; pkg = targ->data;
@ -290,7 +290,7 @@ int _alpm_check_diskspace(alpm_handle_t *handle)
} }
} }
PROGRESS(trans, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", 100, PROGRESS(handle, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", 100,
numtargs, current); numtargs, current);
for(i = mount_points; i; i = i->next) { for(i = mount_points; i; i = i->next) {

View File

@ -166,6 +166,24 @@ alpm_cb_totaldl SYMEXPORT alpm_option_get_totaldlcb(alpm_handle_t *handle)
return handle->totaldlcb; return handle->totaldlcb;
} }
alpm_cb_event SYMEXPORT alpm_option_get_eventcb(alpm_handle_t *handle)
{
CHECK_HANDLE(handle, return NULL);
return handle->eventcb;
}
alpm_cb_conv SYMEXPORT alpm_option_get_convcb(alpm_handle_t *handle)
{
CHECK_HANDLE(handle, return NULL);
return handle->convcb;
}
alpm_cb_progress SYMEXPORT alpm_option_get_progresscb(alpm_handle_t *handle)
{
CHECK_HANDLE(handle, return NULL);
return handle->progresscb;
}
const char SYMEXPORT *alpm_option_get_root(alpm_handle_t *handle) const char SYMEXPORT *alpm_option_get_root(alpm_handle_t *handle)
{ {
CHECK_HANDLE(handle, return NULL); CHECK_HANDLE(handle, return NULL);
@ -290,6 +308,27 @@ int SYMEXPORT alpm_option_set_totaldlcb(alpm_handle_t *handle, alpm_cb_totaldl c
return 0; return 0;
} }
int SYMEXPORT alpm_option_set_eventcb(alpm_handle_t *handle, alpm_cb_event cb)
{
CHECK_HANDLE(handle, return -1);
handle->eventcb = cb;
return 0;
}
int SYMEXPORT alpm_option_set_convcb(alpm_handle_t *handle, alpm_cb_conv cb)
{
CHECK_HANDLE(handle, return -1);
handle->convcb = cb;
return 0;
}
int SYMEXPORT alpm_option_set_progresscb(alpm_handle_t *handle, alpm_cb_progress cb)
{
CHECK_HANDLE(handle, return -1);
handle->progresscb = cb;
return 0;
}
static char *canonicalize_path(const char *path) { static char *canonicalize_path(const char *path) {
char *new_path; char *new_path;
size_t len; size_t len;

View File

@ -30,6 +30,25 @@
#include <curl/curl.h> #include <curl/curl.h>
#endif #endif
#define EVENT(h, e, d1, d2) \
do { \
if((h)->eventcb) { \
(h)->eventcb(e, d1, d2); \
} \
} while(0)
#define QUESTION(h, q, d1, d2, d3, r) \
do { \
if((h)->convcb) { \
(h)->convcb(q, d1, d2, d3, r); \
} \
} while(0)
#define PROGRESS(h, e, p, per, n, r) \
do { \
if((h)->progresscb) { \
(h)->progresscb(e, p, per, n, r); \
} \
} while(0)
struct __alpm_handle_t { struct __alpm_handle_t {
/* internal usage */ /* internal usage */
alpm_db_t *db_local; /* local db pointer */ alpm_db_t *db_local; /* local db pointer */
@ -48,7 +67,10 @@ struct __alpm_handle_t {
alpm_cb_log logcb; /* Log callback function */ alpm_cb_log logcb; /* Log callback function */
alpm_cb_download dlcb; /* Download callback function */ alpm_cb_download dlcb; /* Download callback function */
alpm_cb_totaldl totaldlcb; /* Total download callback function */ alpm_cb_totaldl totaldlcb; /* Total download callback function */
alpm_cb_fetch fetchcb; /* Download file callback function */ alpm_cb_fetch fetchcb; /* Download file callback function */
alpm_cb_event eventcb;
alpm_cb_conv convcb;
alpm_cb_progress progresscb;
/* filesystem paths */ /* filesystem paths */
char *root; /* Root path, default '/' */ char *root; /* Root path, default '/' */

View File

@ -161,7 +161,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
} }
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
EVENT(trans, ALPM_TRANS_EVT_CHECKDEPS_START, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for unsatisfied dependencies\n"); _alpm_log(handle, ALPM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1); lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1);
@ -205,7 +205,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
} }
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
EVENT(trans, ALPM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
} }
return 0; return 0;
@ -362,7 +362,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
_alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n", _alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n",
pkgname, pkgver); pkgname, pkgver);
} else { } else {
EVENT(handle->trans, ALPM_TRANS_EVT_REMOVE_START, oldpkg, NULL); EVENT(handle, ALPM_TRANS_EVT_REMOVE_START, oldpkg, NULL);
_alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n", _alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n",
pkgname, pkgver); pkgname, pkgver);
@ -419,7 +419,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
if(!newpkg) { if(!newpkg) {
/* init progress bar, but only on true remove transactions */ /* init progress bar, but only on true remove transactions */
PROGRESS(handle->trans, ALPM_TRANS_PROGRESS_REMOVE_START, pkgname, 0, PROGRESS(handle, ALPM_TRANS_PROGRESS_REMOVE_START, pkgname, 0,
pkg_count, targ_count); pkg_count, targ_count);
} }
@ -434,7 +434,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
if(!newpkg) { if(!newpkg) {
/* update progress bar after each file */ /* update progress bar after each file */
percent = (position * 100) / filenum; percent = (position * 100) / filenum;
PROGRESS(handle->trans, ALPM_TRANS_PROGRESS_REMOVE_START, pkgname, PROGRESS(handle, ALPM_TRANS_PROGRESS_REMOVE_START, pkgname,
percent, pkg_count, targ_count); percent, pkg_count, targ_count);
} }
position++; position++;
@ -443,7 +443,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
if(!newpkg) { if(!newpkg) {
/* set progress to 100% after we finish unlinking files */ /* set progress to 100% after we finish unlinking files */
PROGRESS(handle->trans, ALPM_TRANS_PROGRESS_REMOVE_START, pkgname, 100, PROGRESS(handle, ALPM_TRANS_PROGRESS_REMOVE_START, pkgname, 100,
pkg_count, targ_count); pkg_count, targ_count);
/* run the post-remove script if it exists */ /* run the post-remove script if it exists */
@ -469,7 +469,7 @@ db:
if(!newpkg) { if(!newpkg) {
/* TODO: awesome! we're passing invalid pointers. */ /* TODO: awesome! we're passing invalid pointers. */
EVENT(handle->trans, ALPM_TRANS_EVT_REMOVE_DONE, oldpkg, NULL); EVENT(handle, ALPM_TRANS_EVT_REMOVE_DONE, oldpkg, NULL);
} }
return 0; return 0;

View File

@ -152,7 +152,7 @@ static alpm_list_t *check_replacers(alpm_handle_t *handle, alpm_pkg_t *lpkg,
continue; continue;
} }
QUESTION(handle->trans, ALPM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, QUESTION(handle, ALPM_TRANS_CONV_REPLACE_PKG, lpkg, spkg,
sdb->treename, &doreplace); sdb->treename, &doreplace);
if(!doreplace) { if(!doreplace) {
continue; continue;
@ -264,7 +264,7 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs,
if(_alpm_pkg_should_ignore(db->handle, pkg)) { if(_alpm_pkg_should_ignore(db->handle, pkg)) {
ignorelist = alpm_list_add(ignorelist, pkg); ignorelist = alpm_list_add(ignorelist, pkg);
int install = 0; int install = 0;
QUESTION(db->handle->trans, ALPM_TRANS_CONV_INSTALL_IGNOREPKG, pkg, QUESTION(db->handle, ALPM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
NULL, NULL, &install); NULL, NULL, &install);
if(!install) if(!install)
continue; continue;
@ -360,7 +360,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
/* Build up list by repeatedly resolving each transaction package */ /* Build up list by repeatedly resolving each transaction package */
/* Resolve targets dependencies */ /* Resolve targets dependencies */
EVENT(trans, ALPM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
_alpm_log(handle, ALPM_LOG_DEBUG, "resolving target's dependencies\n"); _alpm_log(handle, ALPM_LOG_DEBUG, "resolving target's dependencies\n");
/* build remove list for resolvedeps */ /* build remove list for resolvedeps */
@ -393,7 +393,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
see if they'd like to ignore them rather than failing the sync */ see if they'd like to ignore them rather than failing the sync */
if(unresolvable != NULL) { if(unresolvable != NULL) {
int remove_unresolvable = 0; int remove_unresolvable = 0;
QUESTION(trans, ALPM_TRANS_CONV_REMOVE_PKGS, unresolvable, QUESTION(handle, ALPM_TRANS_CONV_REMOVE_PKGS, unresolvable,
NULL, NULL, &remove_unresolvable); NULL, NULL, &remove_unresolvable);
if(remove_unresolvable) { if(remove_unresolvable) {
/* User wants to remove the unresolvable packages from the /* User wants to remove the unresolvable packages from the
@ -431,12 +431,12 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
trans->add = _alpm_sortbydeps(handle, resolved, 0); trans->add = _alpm_sortbydeps(handle, resolved, 0);
alpm_list_free(resolved); alpm_list_free(resolved);
EVENT(trans, ALPM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL);
} }
if(!(trans->flags & ALPM_TRANS_FLAG_NOCONFLICTS)) { if(!(trans->flags & ALPM_TRANS_FLAG_NOCONFLICTS)) {
/* check for inter-conflicts and whatnot */ /* check for inter-conflicts and whatnot */
EVENT(trans, ALPM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL);
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for conflicts\n"); _alpm_log(handle, ALPM_LOG_DEBUG, "looking for conflicts\n");
@ -525,7 +525,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
alpm_pkg_t *sync = _alpm_pkg_find(trans->add, conflict->package1); alpm_pkg_t *sync = _alpm_pkg_find(trans->add, conflict->package1);
alpm_pkg_t *local = _alpm_db_get_pkgfromcache(handle->db_local, conflict->package2); alpm_pkg_t *local = _alpm_db_get_pkgfromcache(handle->db_local, conflict->package2);
int doremove = 0; int doremove = 0;
QUESTION(trans, ALPM_TRANS_CONV_CONFLICT_PKG, conflict->package1, QUESTION(handle, ALPM_TRANS_CONV_CONFLICT_PKG, conflict->package1,
conflict->package2, conflict->reason->name, &doremove); conflict->package2, conflict->reason->name, &doremove);
if(doremove) { if(doremove) {
/* append to the removes list */ /* append to the removes list */
@ -546,7 +546,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
goto cleanup; goto cleanup;
} }
} }
EVENT(trans, ALPM_TRANS_EVT_INTERCONFLICTS_DONE, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_INTERCONFLICTS_DONE, NULL, NULL);
alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free); alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free);
alpm_list_free(deps); alpm_list_free(deps);
} }
@ -646,7 +646,7 @@ static int apply_deltas(alpm_handle_t *handle)
if(!deltas_found) { if(!deltas_found) {
/* only show this if we actually have deltas to apply, and it is before /* only show this if we actually have deltas to apply, and it is before
* the very first one */ * the very first one */
EVENT(trans, ALPM_TRANS_EVT_DELTA_PATCHES_START, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_DELTA_PATCHES_START, NULL, NULL);
deltas_found = 1; deltas_found = 1;
} }
@ -680,11 +680,11 @@ static int apply_deltas(alpm_handle_t *handle)
_alpm_log(handle, ALPM_LOG_DEBUG, "command: %s\n", command); _alpm_log(handle, ALPM_LOG_DEBUG, "command: %s\n", command);
EVENT(trans, ALPM_TRANS_EVT_DELTA_PATCH_START, d->to, d->delta); EVENT(handle, ALPM_TRANS_EVT_DELTA_PATCH_START, d->to, d->delta);
int retval = system(command); int retval = system(command);
if(retval == 0) { if(retval == 0) {
EVENT(trans, ALPM_TRANS_EVT_DELTA_PATCH_DONE, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_DELTA_PATCH_DONE, NULL, NULL);
/* delete the delta file */ /* delete the delta file */
unlink(delta); unlink(delta);
@ -702,7 +702,7 @@ static int apply_deltas(alpm_handle_t *handle)
if(retval != 0) { if(retval != 0) {
/* one delta failed for this package, cancel the remaining ones */ /* one delta failed for this package, cancel the remaining ones */
EVENT(trans, ALPM_TRANS_EVT_DELTA_PATCH_FAILED, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_DELTA_PATCH_FAILED, NULL, NULL);
handle->pm_errno = ALPM_ERR_DLT_PATCHFAILED; handle->pm_errno = ALPM_ERR_DLT_PATCHFAILED;
ret = 1; ret = 1;
break; break;
@ -710,28 +710,25 @@ static int apply_deltas(alpm_handle_t *handle)
} }
} }
if(deltas_found) { if(deltas_found) {
EVENT(trans, ALPM_TRANS_EVT_DELTA_PATCHES_DONE, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_DELTA_PATCHES_DONE, NULL, NULL);
} }
return ret; return ret;
} }
/** Compares the md5sum of a file to the expected value. /**
* * Prompts to delete the file now that we know it is invalid.
* If the md5sum does not match, the user is asked whether the file * @param handle the context handle
* should be deleted.
*
* @param trans the transaction
* @param filename the absolute path of the file to test * @param filename the absolute path of the file to test
* @param reason an error code indicating the reason for package invalidity * @param reason an error code indicating the reason for package invalidity
* *
* @return 1 if file was removed, 0 otherwise * @return 1 if file was removed, 0 otherwise
*/ */
static int prompt_to_delete(alpm_trans_t *trans, const char *filepath, static int prompt_to_delete(alpm_handle_t *handle, const char *filepath,
enum _alpm_errno_t reason) enum _alpm_errno_t reason)
{ {
int doremove = 0; int doremove = 0;
QUESTION(trans, ALPM_TRANS_CONV_CORRUPTED_PKG, (char *)filepath, QUESTION(handle, ALPM_TRANS_CONV_CORRUPTED_PKG, (char *)filepath,
&reason, NULL, &doremove); &reason, NULL, &doremove);
if(doremove) { if(doremove) {
unlink(filepath); unlink(filepath);
@ -744,21 +741,20 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas,
{ {
int errors = 0; int errors = 0;
alpm_list_t *i; alpm_list_t *i;
alpm_trans_t *trans = handle->trans;
if(!deltas) { if(!deltas) {
return 0; return 0;
} }
/* Check integrity of deltas */ /* Check integrity of deltas */
EVENT(trans, ALPM_TRANS_EVT_DELTA_INTEGRITY_START, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_DELTA_INTEGRITY_START, NULL, NULL);
for(i = deltas; i; i = i->next) { for(i = deltas; i; i = i->next) {
alpm_delta_t *d = alpm_list_getdata(i); alpm_delta_t *d = alpm_list_getdata(i);
char *filepath = _alpm_filecache_find(handle, d->delta); char *filepath = _alpm_filecache_find(handle, d->delta);
if(_alpm_test_checksum(filepath, d->delta_md5, ALPM_CSUM_MD5)) { if(_alpm_test_checksum(filepath, d->delta_md5, ALPM_CSUM_MD5)) {
prompt_to_delete(trans, filepath, ALPM_ERR_DLT_INVALID); prompt_to_delete(handle, filepath, ALPM_ERR_DLT_INVALID);
errors++; errors++;
*data = alpm_list_add(*data, strdup(d->delta)); *data = alpm_list_add(*data, strdup(d->delta));
} }
@ -844,7 +840,7 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas)
} }
if(files) { if(files) {
EVENT(handle->trans, ALPM_TRANS_EVT_RETRIEVE_START, current->treename, NULL); EVENT(handle, ALPM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
for(j = files; j; j = j->next) { for(j = files; j; j = j->next) {
struct dload_payload *payload = j->data; struct dload_payload *payload = j->data;
alpm_list_t *server; alpm_list_t *server;
@ -931,7 +927,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
/* Check integrity of packages */ /* Check integrity of packages */
numtargs = alpm_list_count(trans->add); numtargs = alpm_list_count(trans->add);
EVENT(trans, ALPM_TRANS_EVT_INTEGRITY_START, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_INTEGRITY_START, NULL, NULL);
current = current_bytes = 0; current = current_bytes = 0;
errors = 0; errors = 0;
@ -943,7 +939,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
alpm_siglevel_t level; alpm_siglevel_t level;
int percent = (int)(((double)current_bytes / total_bytes) * 100); int percent = (int)(((double)current_bytes / total_bytes) * 100);
PROGRESS(trans, ALPM_TRANS_PROGRESS_INTEGRITY_START, "", percent, PROGRESS(handle, ALPM_TRANS_PROGRESS_INTEGRITY_START, "", percent,
numtargs, current); numtargs, current);
if(spkg->origin == PKG_FROM_FILE) { if(spkg->origin == PKG_FROM_FILE) {
continue; /* pkg_load() has been already called, this package is valid */ continue; /* pkg_load() has been already called, this package is valid */
@ -962,7 +958,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
spkg->name); spkg->name);
alpm_pkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, spkg, 1, level); alpm_pkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, spkg, 1, level);
if(!pkgfile) { if(!pkgfile) {
prompt_to_delete(trans, filepath, handle->pm_errno); prompt_to_delete(handle, filepath, handle->pm_errno);
errors++; errors++;
*data = alpm_list_add(*data, strdup(filename)); *data = alpm_list_add(*data, strdup(filename));
FREE(filepath); FREE(filepath);
@ -974,9 +970,9 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
_alpm_pkg_free_trans(spkg); /* spkg has been removed from the target list */ _alpm_pkg_free_trans(spkg); /* spkg has been removed from the target list */
} }
PROGRESS(trans, ALPM_TRANS_PROGRESS_INTEGRITY_START, "", 100, PROGRESS(handle, ALPM_TRANS_PROGRESS_INTEGRITY_START, "", 100,
numtargs, current); numtargs, current);
EVENT(trans, ALPM_TRANS_EVT_INTEGRITY_DONE, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_INTEGRITY_DONE, NULL, NULL);
if(errors) { if(errors) {
@ -996,7 +992,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
/* fileconflict check */ /* fileconflict check */
if(!(trans->flags & ALPM_TRANS_FLAG_FORCE)) { if(!(trans->flags & ALPM_TRANS_FLAG_FORCE)) {
EVENT(trans, ALPM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL);
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for file conflicts\n"); _alpm_log(handle, ALPM_LOG_DEBUG, "looking for file conflicts\n");
alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle, alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle,
@ -1011,12 +1007,12 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1); RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1);
} }
EVENT(trans, ALPM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL);
} }
/* check available disk space */ /* check available disk space */
if(handle->checkspace) { if(handle->checkspace) {
EVENT(trans, ALPM_TRANS_EVT_DISKSPACE_START, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_DISKSPACE_START, NULL, NULL);
_alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space\n"); _alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space\n");
if(_alpm_check_diskspace(handle) == -1) { if(_alpm_check_diskspace(handle) == -1) {
@ -1024,7 +1020,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
return -1; return -1;
} }
EVENT(trans, ALPM_TRANS_EVT_DISKSPACE_DONE, NULL, NULL); EVENT(handle, ALPM_TRANS_EVT_DISKSPACE_DONE, NULL, NULL);
} }
/* remove conflicting and to-be-replaced packages */ /* remove conflicting and to-be-replaced packages */

View File

@ -48,9 +48,7 @@
*/ */
/** Initialize the transaction. */ /** Initialize the transaction. */
int SYMEXPORT alpm_trans_init(alpm_handle_t *handle, alpm_transflag_t flags, int SYMEXPORT alpm_trans_init(alpm_handle_t *handle, alpm_transflag_t flags)
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress)
{ {
alpm_trans_t *trans; alpm_trans_t *trans;
@ -67,9 +65,6 @@ int SYMEXPORT alpm_trans_init(alpm_handle_t *handle, alpm_transflag_t flags,
CALLOC(trans, 1, sizeof(alpm_trans_t), RET_ERR(handle, ALPM_ERR_MEMORY, -1)); CALLOC(trans, 1, sizeof(alpm_trans_t), RET_ERR(handle, ALPM_ERR_MEMORY, -1));
trans->flags = flags; trans->flags = flags;
trans->cb_event = event;
trans->cb_conv = conv;
trans->cb_progress = progress;
trans->state = STATE_INITIALIZED; trans->state = STATE_INITIALIZED;
handle->trans = trans; handle->trans = trans;

View File

@ -42,34 +42,10 @@ struct __alpm_trans_t {
alpm_list_t *add; /* list of (alpm_pkg_t *) */ alpm_list_t *add; /* list of (alpm_pkg_t *) */
alpm_list_t *remove; /* list of (alpm_pkg_t *) */ alpm_list_t *remove; /* list of (alpm_pkg_t *) */
alpm_list_t *skip_remove; /* list of (char *) */ alpm_list_t *skip_remove; /* list of (char *) */
alpm_trans_cb_event cb_event;
alpm_trans_cb_conv cb_conv;
alpm_trans_cb_progress cb_progress;
}; };
#define EVENT(t, e, d1, d2) \
do { \
if((t)->cb_event) { \
(t)->cb_event(e, d1, d2); \
} \
} while(0)
#define QUESTION(t, q, d1, d2, d3, r) \
do { \
if((t)->cb_conv) { \
(t)->cb_conv(q, d1, d2, d3, r); \
} \
} while(0)
#define PROGRESS(t, e, p, per, h, r) \
do { \
if((t)->cb_progress) { \
(t)->cb_progress(e, p, per, h, r); \
} \
} while(0)
void _alpm_trans_free(alpm_trans_t *trans); void _alpm_trans_free(alpm_trans_t *trans);
int _alpm_trans_init(alpm_trans_t *trans, alpm_transflag_t flags, int _alpm_trans_init(alpm_trans_t *trans, alpm_transflag_t flags);
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress);
int _alpm_runscriptlet(alpm_handle_t *handle, const char *installfn, int _alpm_runscriptlet(alpm_handle_t *handle, const char *installfn,
const char *script, const char *ver, const char *oldver); const char *script, const char *ver, const char *oldver);

View File

@ -569,7 +569,7 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *path, char *const argv[]
if(fgets(line, PATH_MAX, pipe_file) == NULL) if(fgets(line, PATH_MAX, pipe_file) == NULL)
break; break;
alpm_logaction(handle, "%s", line); alpm_logaction(handle, "%s", line);
EVENT(handle->trans, ALPM_TRANS_EVT_SCRIPTLET_INFO, line, NULL); EVENT(handle, ALPM_TRANS_EVT_SCRIPTLET_INFO, line, NULL);
} }
fclose(pipe_file); fclose(pipe_file);
} }

View File

@ -153,6 +153,9 @@ static void fill_progress(const int bar_percent, const int disp_percent,
/* callback to handle messages/notifications from libalpm transactions */ /* callback to handle messages/notifications from libalpm transactions */
void cb_trans_evt(alpm_transevt_t event, void *data1, void *data2) void cb_trans_evt(alpm_transevt_t event, void *data1, void *data2)
{ {
if(config->print) {
return;
}
switch(event) { switch(event) {
case ALPM_TRANS_EVT_CHECKDEPS_START: case ALPM_TRANS_EVT_CHECKDEPS_START:
printf(_("checking dependencies...\n")); printf(_("checking dependencies...\n"));
@ -252,6 +255,9 @@ void cb_trans_evt(alpm_transevt_t event, void *data1, void *data2)
void cb_trans_conv(alpm_transconv_t event, void *data1, void *data2, void cb_trans_conv(alpm_transconv_t event, void *data1, void *data2,
void *data3, int *response) void *data3, int *response)
{ {
if(config->print) {
return;
}
switch(event) { switch(event) {
case ALPM_TRANS_CONV_INSTALL_IGNOREPKG: case ALPM_TRANS_CONV_INSTALL_IGNOREPKG:
if(!config->op_s_downloadonly) { if(!config->op_s_downloadonly) {

View File

@ -534,6 +534,9 @@ static int setup_libalpm(void)
alpm_option_set_logcb(handle, cb_log); alpm_option_set_logcb(handle, cb_log);
alpm_option_set_dlcb(handle, cb_dl_progress); alpm_option_set_dlcb(handle, cb_dl_progress);
alpm_option_set_eventcb(handle, cb_trans_evt);
alpm_option_set_convcb(handle, cb_trans_conv);
alpm_option_set_progresscb(handle, cb_trans_progress);
config->logfile = config->logfile ? config->logfile : strdup(LOGFILE); config->logfile = config->logfile ? config->logfile : strdup(LOGFILE);
ret = alpm_option_set_logfile(handle, config->logfile); ret = alpm_option_set_logfile(handle, config->logfile);

View File

@ -55,13 +55,7 @@ int trans_init(alpm_transflag_t flags, int check_valid)
check_syncdbs(0, check_valid); check_syncdbs(0, check_valid);
if(config->print) { ret = alpm_trans_init(config->handle, flags);
ret = alpm_trans_init(config->handle, flags, NULL, NULL, NULL);
} else {
ret = alpm_trans_init(config->handle, flags, cb_trans_evt, cb_trans_conv,
cb_trans_progress);
}
if(ret == -1) { if(ret == -1) {
trans_init_error(); trans_init_error();
return -1; return -1;