summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-09-01 17:16:56 -0500
committerDan McGee <dan@archlinux.org>2011-09-02 21:45:03 -0500
commit37da18aee8d925ee5cd9f526f2c61d07e9db5b66 (patch)
tree3ed740826f4463c8779080b07b57adbde1fe5c3b /lib/libalpm
parentd88e524e7c6e902dcf1c0afed52def0d8b430b25 (diff)
downloadpacman-37da18aee8d925ee5cd9f526f2c61d07e9db5b66.tar.xz
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>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/add.c20
-rw-r--r--lib/libalpm/alpm.h41
-rw-r--r--lib/libalpm/conflict.c5
-rw-r--r--lib/libalpm/deps.c6
-rw-r--r--lib/libalpm/diskspace.c6
-rw-r--r--lib/libalpm/handle.c39
-rw-r--r--lib/libalpm/handle.h24
-rw-r--r--lib/libalpm/remove.c14
-rw-r--r--lib/libalpm/sync.c64
-rw-r--r--lib/libalpm/trans.c7
-rw-r--r--lib/libalpm/trans.h26
-rw-r--r--lib/libalpm/util.c2
12 files changed, 145 insertions, 109 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index cb8551e8..96272a25 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -473,7 +473,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
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",
newpkg->name, newpkg->version);
@@ -488,7 +488,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
} else {
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",
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 */
if(is_upgrade) {
- PROGRESS(trans, ALPM_TRANS_PROGRESS_UPGRADE_START,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_UPGRADE_START,
newpkg->name, 0, pkg_count, pkg_current);
} else {
- PROGRESS(trans, ALPM_TRANS_PROGRESS_ADD_START,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_ADD_START,
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) {
- PROGRESS(trans, ALPM_TRANS_PROGRESS_UPGRADE_START,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_UPGRADE_START,
newpkg->name, percent, pkg_count, pkg_current);
} else {
- PROGRESS(trans, ALPM_TRANS_PROGRESS_ADD_START,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_ADD_START,
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) {
- PROGRESS(trans, ALPM_TRANS_PROGRESS_UPGRADE_START,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_UPGRADE_START,
newpkg->name, 100, pkg_count, pkg_current);
} else {
- PROGRESS(trans, ALPM_TRANS_PROGRESS_ADD_START,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_ADD_START,
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) {
- EVENT(trans, ALPM_TRANS_EVT_UPGRADE_DONE, newpkg, oldpkg);
+ EVENT(handle, ALPM_TRANS_EVT_UPGRADE_DONE, newpkg, oldpkg);
} else {
- EVENT(trans, ALPM_TRANS_EVT_ADD_DONE, newpkg, oldpkg);
+ EVENT(handle, ALPM_TRANS_EVT_ADD_DONE, newpkg, oldpkg);
}
cleanup:
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index cfc2a100..d2512ff2 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -863,7 +863,7 @@ typedef enum _alpm_transflag_t {
ALPM_TRANS_FLAG_NOLOCK = (1 << 17)
} alpm_transflag_t;
-/** Transaction events.
+/** Events.
* NULL parameters are passed to in all events unless specified otherwise.
*/
typedef enum _alpm_transevt_t {
@@ -943,7 +943,7 @@ typedef enum _alpm_transevt_t {
ALPM_TRANS_EVT_DISKSPACE_DONE,
} alpm_transevt_t;
-/** Transaction Conversations (ie, questions) */
+/** Conversations (ie, questions) */
typedef enum _alpm_transconv_t {
ALPM_TRANS_CONV_INSTALL_IGNOREPKG = 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_transconv_t;
-/** Transaction Progress */
+/** Progress */
typedef enum _alpm_transprog_t {
ALPM_TRANS_PROGRESS_ADD_START,
ALPM_TRANS_PROGRESS_UPGRADE_START,
@@ -964,15 +964,29 @@ typedef enum _alpm_transprog_t {
ALPM_TRANS_PROGRESS_INTEGRITY_START,
} alpm_transprog_t;
-/** Transaction Event callback */
-typedef void (*alpm_trans_cb_event)(alpm_transevt_t, void *, void *);
+/** Event callback */
+typedef void (*alpm_cb_event)(alpm_transevt_t, void *, void *);
-/** Transaction Conversation callback */
-typedef void (*alpm_trans_cb_conv)(alpm_transconv_t, void *, void *,
- void *, int *);
+/** Conversation callback */
+typedef void (*alpm_cb_conv)(alpm_transconv_t, void *, void *, void *, int *);
-/** Transaction Progress callback */
-typedef void (*alpm_trans_cb_progress)(alpm_transprog_t, const char *, int, size_t, size_t);
+/** Progress callback */
+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.
* @param handle the context handle
@@ -995,14 +1009,9 @@ alpm_list_t *alpm_trans_get_remove(alpm_handle_t *handle);
/** Initialize the transaction.
* @param handle the context handle
* @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)
*/
-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);
+int alpm_trans_init(alpm_handle_t *handle, alpm_transflag_t flags);
/** Prepare a transaction.
* @param handle the context handle
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 8417348a..4f96ad9a 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -384,7 +384,6 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
alpm_list_t *i, *conflicts = NULL;
size_t numtargs = alpm_list_count(upgrade);
size_t current;
- alpm_trans_t *trans = handle->trans;
if(!upgrade) {
return NULL;
@@ -402,7 +401,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
size_t filenum;
int percent = (current * 100) / numtargs;
- PROGRESS(trans, ALPM_TRANS_PROGRESS_CONFLICTS_START, "", percent,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_CONFLICTS_START, "", percent,
numtargs, current);
/* CHECK 1: check every target against every target */
_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);
}
}
- PROGRESS(trans, ALPM_TRANS_PROGRESS_CONFLICTS_START, "", 100,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_CONFLICTS_START, "", 100,
numtargs, current);
return conflicts;
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 639f14ba..104c97ba 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -582,7 +582,7 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
if(_alpm_pkg_should_ignore(handle, pkg)) {
int install = 0;
if(prompt) {
- QUESTION(handle->trans, ALPM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
+ QUESTION(handle, ALPM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
NULL, NULL, &install);
} else {
_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)) {
int install = 0;
if(prompt) {
- QUESTION(handle->trans, ALPM_TRANS_CONV_INSTALL_IGNOREPKG,
+ QUESTION(handle, ALPM_TRANS_CONV_INSTALL_IGNOREPKG,
pkg, NULL, NULL, &install);
} else {
_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;
if(count > 1) {
/* 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);
}
if(index >= 0 && index < count) {
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index ad80304b..f791c07b 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -260,7 +260,7 @@ int _alpm_check_diskspace(alpm_handle_t *handle)
for(targ = trans->remove; targ; targ = targ->next, current++) {
alpm_pkg_t *local_pkg;
int percent = (current * 100) / numtargs;
- PROGRESS(trans, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current);
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++) {
alpm_pkg_t *pkg, *local_pkg;
int percent = (current * 100) / numtargs;
- PROGRESS(trans, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_DISKSPACE_START, "", percent,
numtargs, current);
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);
for(i = mount_points; i; i = i->next) {
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index b9d71db8..bc968c72 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -166,6 +166,24 @@ alpm_cb_totaldl SYMEXPORT alpm_option_get_totaldlcb(alpm_handle_t *handle)
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)
{
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;
}
+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) {
char *new_path;
size_t len;
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 9e038581..8ceecd32 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -30,6 +30,25 @@
#include <curl/curl.h>
#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 {
/* internal usage */
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_download dlcb; /* 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 */
char *root; /* Root path, default '/' */
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 7903a0f5..8867f651 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -161,7 +161,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
}
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");
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)) {
- EVENT(trans, ALPM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
+ EVENT(handle, ALPM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
}
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",
pkgname, pkgver);
} 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",
pkgname, pkgver);
@@ -419,7 +419,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
if(!newpkg) {
/* 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);
}
@@ -434,7 +434,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
if(!newpkg) {
/* update progress bar after each file */
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);
}
position++;
@@ -443,7 +443,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
if(!newpkg) {
/* 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);
/* run the post-remove script if it exists */
@@ -469,7 +469,7 @@ db:
if(!newpkg) {
/* 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;
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index f125b4a6..95b5f9dc 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -152,7 +152,7 @@ static alpm_list_t *check_replacers(alpm_handle_t *handle, alpm_pkg_t *lpkg,
continue;
}
- QUESTION(handle->trans, ALPM_TRANS_CONV_REPLACE_PKG, lpkg, spkg,
+ QUESTION(handle, ALPM_TRANS_CONV_REPLACE_PKG, lpkg, spkg,
sdb->treename, &doreplace);
if(!doreplace) {
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)) {
ignorelist = alpm_list_add(ignorelist, pkg);
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);
if(!install)
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 */
/* 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");
/* 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 */
if(unresolvable != NULL) {
int remove_unresolvable = 0;
- QUESTION(trans, ALPM_TRANS_CONV_REMOVE_PKGS, unresolvable,
+ QUESTION(handle, ALPM_TRANS_CONV_REMOVE_PKGS, unresolvable,
NULL, NULL, &remove_unresolvable);
if(remove_unresolvable) {
/* 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);
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)) {
/* 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");
@@ -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 *local = _alpm_db_get_pkgfromcache(handle->db_local, conflict->package2);
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);
if(doremove) {
/* append to the removes list */
@@ -546,7 +546,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
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(deps);
}
@@ -646,7 +646,7 @@ static int apply_deltas(alpm_handle_t *handle)
if(!deltas_found) {
/* only show this if we actually have deltas to apply, and it is before
* 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;
}
@@ -680,11 +680,11 @@ static int apply_deltas(alpm_handle_t *handle)
_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);
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 */
unlink(delta);
@@ -702,7 +702,7 @@ static int apply_deltas(alpm_handle_t *handle)
if(retval != 0) {
/* 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;
ret = 1;
break;
@@ -710,28 +710,25 @@ static int apply_deltas(alpm_handle_t *handle)
}
}
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;
}
-/** Compares the md5sum of a file to the expected value.
- *
- * If the md5sum does not match, the user is asked whether the file
- * should be deleted.
- *
- * @param trans the transaction
+/**
+ * Prompts to delete the file now that we know it is invalid.
+ * @param handle the context handle
* @param filename the absolute path of the file to test
* @param reason an error code indicating the reason for package invalidity
*
* @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)
{
int doremove = 0;
- QUESTION(trans, ALPM_TRANS_CONV_CORRUPTED_PKG, (char *)filepath,
+ QUESTION(handle, ALPM_TRANS_CONV_CORRUPTED_PKG, (char *)filepath,
&reason, NULL, &doremove);
if(doremove) {
unlink(filepath);
@@ -744,21 +741,20 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas,
{
int errors = 0;
alpm_list_t *i;
- alpm_trans_t *trans = handle->trans;
if(!deltas) {
return 0;
}
/* 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) {
alpm_delta_t *d = alpm_list_getdata(i);
char *filepath = _alpm_filecache_find(handle, d->delta);
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++;
*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) {
- 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) {
struct dload_payload *payload = j->data;
alpm_list_t *server;
@@ -931,7 +927,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
/* Check integrity of packages */
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;
errors = 0;
@@ -943,7 +939,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
alpm_siglevel_t level;
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);
if(spkg->origin == PKG_FROM_FILE) {
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);
alpm_pkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, spkg, 1, level);
if(!pkgfile) {
- prompt_to_delete(trans, filepath, handle->pm_errno);
+ prompt_to_delete(handle, filepath, handle->pm_errno);
errors++;
*data = alpm_list_add(*data, strdup(filename));
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 */
}
- PROGRESS(trans, ALPM_TRANS_PROGRESS_INTEGRITY_START, "", 100,
+ PROGRESS(handle, ALPM_TRANS_PROGRESS_INTEGRITY_START, "", 100,
numtargs, current);
- EVENT(trans, ALPM_TRANS_EVT_INTEGRITY_DONE, NULL, NULL);
+ EVENT(handle, ALPM_TRANS_EVT_INTEGRITY_DONE, NULL, NULL);
if(errors) {
@@ -996,7 +992,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
/* fileconflict check */
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_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);
}
- EVENT(trans, ALPM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL);
+ EVENT(handle, ALPM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL);
}
/* check available disk space */
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");
if(_alpm_check_diskspace(handle) == -1) {
@@ -1024,7 +1020,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
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 */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index c594520d..47b9c98d 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -48,9 +48,7 @@
*/
/** Initialize the transaction. */
-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)
+int SYMEXPORT alpm_trans_init(alpm_handle_t *handle, alpm_transflag_t flags)
{
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));
trans->flags = flags;
- trans->cb_event = event;
- trans->cb_conv = conv;
- trans->cb_progress = progress;
trans->state = STATE_INITIALIZED;
handle->trans = trans;
diff --git a/lib/libalpm/trans.h b/lib/libalpm/trans.h
index 6d5c08d1..a2be5a5c 100644
--- a/lib/libalpm/trans.h
+++ b/lib/libalpm/trans.h
@@ -42,34 +42,10 @@ struct __alpm_trans_t {
alpm_list_t *add; /* list of (alpm_pkg_t *) */
alpm_list_t *remove; /* list of (alpm_pkg_t *) */
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);
-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_trans_init(alpm_trans_t *trans, alpm_transflag_t flags);
int _alpm_runscriptlet(alpm_handle_t *handle, const char *installfn,
const char *script, const char *ver, const char *oldver);
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 9bbac43b..161a35a9 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -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)
break;
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);
}