summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/add.c8
-rw-r--r--lib/libalpm/alpm.h1
-rw-r--r--lib/libalpm/db.c6
-rw-r--r--lib/libalpm/remove.c5
-rw-r--r--lib/libalpm/trans.c34
5 files changed, 31 insertions, 23 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 3f9a2a85..98906879 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -905,7 +905,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* loop through our package list adding/upgrading one at a time */
for(targ = trans->packages; targ; targ = targ->next) {
if(handle->trans->state == STATE_INTERRUPTED) {
- break;
+ return(0);
}
pmpkg_t *newpkg = (pmpkg_t *)targ->data;
@@ -914,10 +914,8 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
}
/* run ldconfig if it exists */
- if(handle->trans->state != STATE_INTERRUPTED) {
- _alpm_log(PM_LOG_DEBUG, "running \"ldconfig -r %s\"\n", handle->root);
- _alpm_ldconfig(handle->root);
- }
+ _alpm_log(PM_LOG_DEBUG, "running \"ldconfig -r %s\"\n", handle->root);
+ _alpm_ldconfig(handle->root);
return(0);
}
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 81137e6d..4a44cc76 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -335,6 +335,7 @@ int alpm_trans_sysupgrade(void);
int alpm_trans_addtarget(char *target);
int alpm_trans_prepare(alpm_list_t **data);
int alpm_trans_commit(alpm_list_t **data);
+int alpm_trans_interrupt(void);
int alpm_trans_release(void);
/*
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 61c74a77..b06a970c 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -111,8 +111,7 @@ int SYMEXPORT alpm_db_unregister_all(void)
/* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
/* Do not unregister a database if a transaction is on-going */
- ASSERT(handle->trans == NULL || handle->trans->state == STATE_INTERRUPTED,
- RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
+ ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
/* close local database */
_alpm_db_unregister(handle->db_local);
@@ -142,8 +141,7 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
ASSERT(db != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
/* Do not unregister a database if a transaction is on-going */
- ASSERT(handle->trans == NULL || handle->trans->state == STATE_INTERRUPTED,
- RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
+ ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
if(db == handle->db_local) {
handle->db_local = NULL;
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 010e7ab6..fb5ddb92 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -280,7 +280,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
const char *pkgname = NULL;
if(handle->trans->state == STATE_INTERRUPTED) {
- break;
+ return(0);
}
/* get the name now so we can use it after package is removed */
@@ -360,8 +360,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
}
/* run ldconfig if it exists */
- if((trans->type != PM_TRANS_TYPE_REMOVEUPGRADE)
- && (handle->trans->state != STATE_INTERRUPTED)) {
+ if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
_alpm_log(PM_LOG_DEBUG, "running \"ldconfig -r %s\"\n", handle->root);
_alpm_ldconfig(handle->root);
}
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index fe37a1f9..9eb27c30 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -165,13 +165,34 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
return(_alpm_trans_commit(handle->trans, data));
}
+/** Interrupt a transaction.
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int SYMEXPORT alpm_trans_interrupt()
+{
+ pmtrans_t *trans;
+
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+
+ trans = handle->trans;
+ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state == STATE_COMMITING || trans->state == STATE_INTERRUPTED,
+ RET_ERR(PM_ERR_TRANS_TYPE, -1));
+
+ trans->state = STATE_INTERRUPTED;
+
+ return(0);
+}
+
/** Release a transaction.
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
int SYMEXPORT alpm_trans_release()
{
pmtrans_t *trans;
- int ret = 0;
ALPM_LOG_FUNC;
@@ -182,15 +203,6 @@ int SYMEXPORT alpm_trans_release()
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(trans->state != STATE_IDLE, RET_ERR(PM_ERR_TRANS_NULL, -1));
- /* during a commit do not interrupt immediately, just after a target */
- if(trans->state == STATE_COMMITING || trans->state == STATE_INTERRUPTED) {
- if(trans->state == STATE_COMMITING) {
- trans->state = STATE_INTERRUPTED;
- }
- pm_errno = PM_ERR_TRANS_COMMITING;
- ret = -1;
- }
-
_alpm_trans_free(trans);
handle->trans = NULL;
@@ -206,7 +218,7 @@ int SYMEXPORT alpm_trans_release()
alpm_option_get_lockfile());
}
- return(ret);
+ return(0);
}
/** @} */