summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2015-09-14 18:37:40 -0400
committerAllan McRae <allan@archlinux.org>2015-09-20 17:36:53 +1000
commit6946d7d1b77a550c3f4de48e4cc6ad1094ac6b10 (patch)
tree70536168605c0ced9d469c126c764193fcfa69c8 /lib
parentaf747ef34a9a152614fcde18abcfc6e1e3ec5d0e (diff)
check fileconflicts and diskspace outside commit
This is necessary in order to be able to run PreTransaction hooks as close to the actual commit as possible so that we don't prematurely run hooks for a transaction that ultimately never happens. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/sync.c18
-rw-r--r--lib/libalpm/sync.h3
-rw-r--r--lib/libalpm/trans.c6
3 files changed, 21 insertions, 6 deletions
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index e843b07a..c5607bc8 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -1338,7 +1338,7 @@ int _alpm_sync_load(alpm_handle_t *handle, alpm_list_t **data)
return 0;
}
-int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
+int _alpm_sync_check(alpm_handle_t *handle, alpm_list_t **data)
{
alpm_trans_t *trans = handle->trans;
alpm_event_t event;
@@ -1355,7 +1355,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
if(data) {
*data = conflict;
} else {
- alpm_list_free_inner(conflict, (alpm_list_fn_free)alpm_fileconflict_free);
+ alpm_list_free_inner(conflict,
+ (alpm_list_fn_free)alpm_fileconflict_free);
alpm_list_free(conflict);
}
RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1);
@@ -1380,12 +1381,21 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
EVENT(handle, &event);
}
+ return 0;
+}
+
+int _alpm_sync_commit(alpm_handle_t *handle)
+{
+ alpm_trans_t *trans = handle->trans;
+
/* remove conflicting and to-be-replaced packages */
if(trans->remove) {
- _alpm_log(handle, ALPM_LOG_DEBUG, "removing conflicting and to-be-replaced packages\n");
+ _alpm_log(handle, ALPM_LOG_DEBUG,
+ "removing conflicting and to-be-replaced packages\n");
/* we want the frontend to be aware of commit details */
if(_alpm_remove_packages(handle, 0) == -1) {
- _alpm_log(handle, ALPM_LOG_ERROR, _("could not commit removal transaction\n"));
+ _alpm_log(handle, ALPM_LOG_ERROR,
+ _("could not commit removal transaction\n"));
return -1;
}
}
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index 6281550f..60ebb750 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -26,7 +26,8 @@
int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data);
int _alpm_sync_load(alpm_handle_t *handle, alpm_list_t **data);
-int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data);
+int _alpm_sync_check(alpm_handle_t *handle, alpm_list_t **data);
+int _alpm_sync_commit(alpm_handle_t *handle);
#endif /* _ALPM_SYNC_H */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 6a26e753..ed073c09 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -183,6 +183,10 @@ int SYMEXPORT alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data)
if(trans->flags & ALPM_TRANS_FLAG_DOWNLOADONLY) {
return 0;
}
+ if(_alpm_sync_check(handle, data) != 0) {
+ /* pm_errno is set by _alpm_sync_check() */
+ return -1;
+ }
}
trans->state = STATE_COMMITING;
@@ -198,7 +202,7 @@ int SYMEXPORT alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data)
return -1;
}
} else {
- if(_alpm_sync_commit(handle, data) == -1) {
+ if(_alpm_sync_commit(handle) == -1) {
/* pm_errno is set by _alpm_sync_commit() */
alpm_errno_t save = handle->pm_errno;
alpm_logaction(handle, ALPM_CALLER_PREFIX, "transaction failed\n");