1
0
mirror of https://github.com/moparisthebest/pacman synced 2025-02-28 17:31:52 -05:00

event transaction callback rework to prepare the introduction of a conversation callback

This commit is contained in:
Aurelien Foret 2005-05-04 19:55:23 +00:00
parent 14c8583ccb
commit a26095f8fc
7 changed files with 33 additions and 30 deletions

View File

@ -200,7 +200,7 @@ int add_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
PMList *i;
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "looking for conflicts or unsatisfied dependencies");
lp = checkdeps(db, trans->type, trans->packages);
@ -257,13 +257,13 @@ int add_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
FREELISTPTR(trans->packages);
trans->packages = lp;
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
}
/* Check for file conflicts
*/
if(!(trans->flags & PM_TRANS_FLAG_FORCE)) {
TRANS_CB(trans, PM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "looking for file conflicts");
lp = db_find_conflicts(db, trans->packages, handle->root);
@ -272,7 +272,7 @@ int add_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
RET_ERR(PM_ERR_FILE_CONFLICTS, -1);
}
TRANS_CB(trans, PM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL);
}
return(0);
@ -312,7 +312,7 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
if(pmo_upgrade) {
pmpkg_t *local = db_get_pkgfromcache(db, info->name);
if(local) {
TRANS_CB(trans, PM_TRANS_EVT_UPGRADE_START, info, NULL);
EVENT(trans, PM_TRANS_EVT_UPGRADE_START, info, NULL);
_alpm_log(PM_LOG_FLOW1, "upgrading package %s-%s", info->name, info->version);
/* we'll need to save some record for backup checks later */
@ -360,7 +360,7 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
}
}
if(!pmo_upgrade) {
TRANS_CB(trans, PM_TRANS_EVT_ADD_START, info, NULL);
EVENT(trans, PM_TRANS_EVT_ADD_START, info, NULL);
_alpm_log(PM_LOG_FLOW1, "adding package %s-%s", info->name, info->version);
/* pre_install scriptlet */
@ -656,11 +656,11 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
}
if(pmo_upgrade) {
TRANS_CB(trans, PM_TRANS_EVT_UPGRADE_DONE, info, NULL);
EVENT(trans, PM_TRANS_EVT_UPGRADE_DONE, info, NULL);
alpm_logaction("upgraded %s (%s -> %s)", info->name,
oldpkg ? oldpkg->version : NULL, info->version);
} else {
TRANS_CB(trans, PM_TRANS_EVT_ADD_DONE, info, NULL);
EVENT(trans, PM_TRANS_EVT_ADD_DONE, info, NULL);
alpm_logaction("installed %s (%s)", info->name, info->version);
}

View File

@ -541,7 +541,7 @@ void *alpm_trans_getinfo(unsigned char parm)
return(data);
}
int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb cb)
int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb_event event)
{
/* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
@ -553,7 +553,7 @@ int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb cb)
RET_ERR(PM_ERR_MEMORY, -1);
}
return(trans_init(handle->trans, type, flags, cb));
return(trans_init(handle->trans, type, flags, event));
}
int alpm_trans_sysupgrade()

View File

@ -229,7 +229,10 @@ enum {
};
/* Event callback */
typedef void (*alpm_trans_cb)(unsigned short, void *, void *);
typedef void (*alpm_trans_cb_event)(unsigned char, void *, void *);
/* Conversation callback */
typedef void (*alpm_trans_cb_conv)(unsigned char, void *, void *);
/* Info parameters */
enum {
@ -240,7 +243,7 @@ enum {
};
void *alpm_trans_getinfo(unsigned char parm);
int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb cb);
int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb_event cb_event);
int alpm_trans_sysupgrade();
int alpm_trans_addtarget(char *target);
int alpm_trans_prepare(PM_LIST **data);

View File

@ -81,7 +81,7 @@ int remove_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
if(!(trans->flags & (PM_TRANS_FLAG_NODEPS)) && (trans->type != PM_TRANS_TYPE_UPGRADE)) {
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "looking for unsatisfied dependencies");
if((lp = checkdeps(db, trans->type, trans->packages)) != NULL) {
@ -119,7 +119,7 @@ int remove_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
FREELISTPTR(trans->packages);
trans->packages = lp;
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
}
return(0);
@ -147,7 +147,7 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
info = (pmpkg_t*)targ->data;
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
TRANS_CB(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
_alpm_log(PM_LOG_FLOW1, "removing package %s-%s", info->name, info->version);
/* run the pre-remove scriptlet if it exists */
@ -273,7 +273,7 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
}
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
TRANS_CB(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
alpm_logaction("removed %s (%s)", info->name, info->version);
}
}

View File

@ -344,7 +344,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
trail = pm_list_new();
/* Resolve targets dependencies */
TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "resolving targets dependencies");
for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data;
@ -362,10 +362,10 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
trans->packages = pm_list_add(trans->packages, sync);
}
}
TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL);
/* check for inter-conflicts and whatnot */
TRANS_CB(trans, PM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL);
deps = checkdeps(db_local, PM_TRANS_TYPE_UPGRADE, list);
if(deps) {
int found;
@ -431,7 +431,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
RET_ERR(PM_ERR_CONFLICTING_DEPS, -1);
}
}
TRANS_CB(trans, PM_TRANS_EVT_INTERCONFLICTS_DONE, NULL, NULL);
EVENT(trans, PM_TRANS_EVT_INTERCONFLICTS_DONE, NULL, NULL);
FREELISTPTR(list);
FREELISTPTR(trail);
@ -511,7 +511,7 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
goto error;
}
/* we want the frontend to be aware of commit details */
tr->cb = trans->cb;
tr->cb_event = trans->cb_event;
if(trans_commit(tr) == -1) {
_alpm_log(PM_LOG_ERROR, "could not commit removal transaction");
pm_errno = PM_ERR_XXX;
@ -558,7 +558,7 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
goto error;
}
/* we want the frontend to be aware of commit details */
tr->cb = trans->cb;
tr->cb_event = trans->cb_event;
if(trans_commit(tr) == -1) {
_alpm_log(PM_LOG_ERROR, "could not commit transaction");
pm_errno = PM_ERR_XXX;

View File

@ -48,7 +48,7 @@ pmtrans_t *trans_new()
trans->packages = NULL;
trans->type = 0;
trans->flags = 0;
trans->cb = NULL;
trans->cb_event = NULL;
trans->state = STATE_IDLE;
return(trans);
@ -75,7 +75,7 @@ void trans_free(pmtrans_t *trans)
free(trans);
}
int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_trans_cb cb)
int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_trans_cb_event event)
{
/* Sanity checks */
if(trans == NULL) {
@ -88,7 +88,7 @@ int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_t
trans->type = type;
trans->flags = flags;
trans->cb = cb;
trans->cb_event = event;
trans->state = STATE_INITIALIZED;
return(0);

View File

@ -36,7 +36,7 @@ typedef struct __pmtrans_t {
unsigned char state;
PMList *targets; /* PMList of (char *) */
PMList *packages; /* PMList of (pmpkg_t *) or (pmsyncpkg_t *) */
alpm_trans_cb cb;
alpm_trans_cb_event cb_event;
} pmtrans_t;
#define FREETRANS(p) \
@ -46,16 +46,16 @@ do { \
p = NULL; \
} \
} while (0)
#define TRANS_CB(t, e, d1, d2) \
#define EVENT(t, e, d1, d2) \
do { \
if((t) && (t)->cb) { \
(t)->cb(e, d1, d2); \
if((t) && (t)->cb_event) { \
(t)->cb_event(e, d1, d2); \
} \
} while(0)
pmtrans_t *trans_new();
void trans_free(pmtrans_t *trans);
int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_trans_cb cb);
int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_trans_cb_event event);
int trans_sysupgrade(pmtrans_t *trans);
int trans_addtarget(pmtrans_t *trans, char *target);
int trans_prepare(pmtrans_t *trans, PMList **data);