mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-21 23:38:49 -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:
parent
d88e524e7c
commit
37da18aee8
7
README
7
README
@ -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_db_setserver() replaced by alpm_db_set_servers(), alpm_db_add_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 *:
|
||||
- alpm_option_get_*
|
||||
- alpm_option_set_*
|
||||
@ -425,10 +427,13 @@ API CHANGES BETWEEN 3.5 AND 4.0
|
||||
- alpm_pkg_reason_t
|
||||
|
||||
[ADDED]
|
||||
- option functions:
|
||||
alpm_{get,set}_eventcb(), alpm_option_{get,set}_convcb(),
|
||||
alpm_option_{get,set}_progresscb()
|
||||
- package signing functions:
|
||||
alpm_option_get_default_siglevel(), alpm_option_set_default_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()
|
||||
- list functions:
|
||||
alpm_list_to_array(), alpm_list_previous()
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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 '/' */
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -153,6 +153,9 @@ static void fill_progress(const int bar_percent, const int disp_percent,
|
||||
/* callback to handle messages/notifications from libalpm transactions */
|
||||
void cb_trans_evt(alpm_transevt_t event, void *data1, void *data2)
|
||||
{
|
||||
if(config->print) {
|
||||
return;
|
||||
}
|
||||
switch(event) {
|
||||
case ALPM_TRANS_EVT_CHECKDEPS_START:
|
||||
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 *data3, int *response)
|
||||
{
|
||||
if(config->print) {
|
||||
return;
|
||||
}
|
||||
switch(event) {
|
||||
case ALPM_TRANS_CONV_INSTALL_IGNOREPKG:
|
||||
if(!config->op_s_downloadonly) {
|
||||
|
@ -534,6 +534,9 @@ static int setup_libalpm(void)
|
||||
|
||||
alpm_option_set_logcb(handle, cb_log);
|
||||
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);
|
||||
ret = alpm_option_set_logfile(handle, config->logfile);
|
||||
|
@ -55,13 +55,7 @@ int trans_init(alpm_transflag_t flags, int check_valid)
|
||||
|
||||
check_syncdbs(0, check_valid);
|
||||
|
||||
if(config->print) {
|
||||
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);
|
||||
}
|
||||
|
||||
ret = alpm_trans_init(config->handle, flags);
|
||||
if(ret == -1) {
|
||||
trans_init_error();
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user