[pacman-dev] [PATCH v2] alpm: Abort ASAP on failure in pre-transaction hooks
Olivier Brunel
jjk at jjacky.com
Tue Dec 15 08:14:37 UTC 2015
There is no need to run any/remaining pre-transaction hooks as soon as a failure
has occured, which will lead to aborting the transaction.
So if an error occured during the first phase (reading directories/parsing
files), or as soon as a hook flagged abort_on_fail does fail, we stop processing
them and return.
(For post-transaction hooks, all hooks are run regardless since there's no
aborting.)
v2: Don't stop during first phase, so e.g. all parsing errors can be found &
reported at once.
Signed-off-by: Olivier Brunel <jjk at jjacky.com>
---
lib/libalpm/hook.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/lib/libalpm/hook.c b/lib/libalpm/hook.c
index acd571d..74d7a5b 100644
--- a/lib/libalpm/hook.c
+++ b/lib/libalpm/hook.c
@@ -708,6 +708,10 @@ int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when)
closedir(d);
}
+ if(ret != 0 && when == ALPM_HOOK_PRE_TRANSACTION) {
+ goto cleanup;
+ }
+
hooks = alpm_list_msort(hooks, alpm_list_count(hooks),
(alpm_list_fn_cmp)_alpm_hook_cmp);
@@ -743,6 +747,10 @@ int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when)
hook_event.type = ALPM_EVENT_HOOK_RUN_DONE;
EVENT(handle, &hook_event);
+
+ if(ret != 0 && when == ALPM_HOOK_PRE_TRANSACTION) {
+ break;
+ }
}
event.type = ALPM_EVENT_HOOK_DONE;
--
2.6.4
More information about the pacman-dev
mailing list