summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2015-12-14 20:23:26 +1000
committerAllan McRae <allan@archlinux.org>2015-12-15 20:15:02 +1000
commitd721bae443fe020bf755d0440684a17b75de970f (patch)
tree971187b77dedb5d02c535ca5237be5b19fa9a388
parent760bea543211673884c254b7e0c44e0f70fe2257 (diff)
downloadpacman-d721bae443fe020bf755d0440684a17b75de970f.tar.xz
alpm-hooks: add Description field
The "Description" field allows a hook to provide a some text for frontends to use in describing what the hook is doing. For example: Description = updating info page directory Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--doc/alpm-hooks.5.txt5
-rw-r--r--lib/libalpm/alpm.h2
-rw-r--r--lib/libalpm/hook.c5
-rw-r--r--src/pacman/callback.c3
4 files changed, 14 insertions, 1 deletions
diff --git a/doc/alpm-hooks.5.txt b/doc/alpm-hooks.5.txt
index 3729387c..f33ff8cd 100644
--- a/doc/alpm-hooks.5.txt
+++ b/doc/alpm-hooks.5.txt
@@ -19,6 +19,7 @@ Type = File|Package (Required)
Target = <Path|PkgName> (Required, Repeatable)
[Action] (Required)
+Description = ... (Optional)
When = PreTransaction|PostTransaction (Required)
Exec = <Command> (Required)
Depends = <PkgName> (Optional)
@@ -63,6 +64,10 @@ defined the hook will run if the transaction matches *any* of the triggers.
ACTIONS
-------
+* Description =* ...::
+ An optional description that describes the action being taken by the
+ hook for use in front-end output.
+
*Exec =* <command>::
Command to run. Command arguments are split on whitespace. Values
containing whitespace should be enclosed in quotes. Required.
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 337104e0..fba25ab8 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -568,6 +568,8 @@ typedef struct _alpm_event_hook_run_t {
alpm_event_type_t type;
/** Name of hook */
const char *name;
+ /** Description of hook to be outputted */
+ const char *desc;
/** position of hook being run */
size_t position;
/** total hooks being run */
diff --git a/lib/libalpm/hook.c b/lib/libalpm/hook.c
index 804cfa57..fd251fa9 100644
--- a/lib/libalpm/hook.c
+++ b/lib/libalpm/hook.c
@@ -48,6 +48,7 @@ struct _alpm_trigger_t {
struct _alpm_hook_t {
char *name;
+ char *desc;
alpm_list_t *triggers;
alpm_list_t *depends;
char **cmd;
@@ -84,6 +85,7 @@ static void _alpm_hook_free(struct _alpm_hook_t *hook)
{
if(hook) {
free(hook->name);
+ free(hook->desc);
_alpm_wordsplit_free(hook->cmd);
alpm_list_free_inner(hook->triggers, (alpm_list_fn_free) _alpm_trigger_free);
alpm_list_free(hook->triggers);
@@ -316,6 +318,8 @@ static int _alpm_hook_parse_cb(const char *file, int line,
} else {
error(_("hook %s line %d: invalid value %s\n"), file, line, value);
}
+ } else if(strcmp(key, "Description") == 0) {
+ STRDUP(hook->desc, value, return 1);
} else if(strcmp(key, "Depends") == 0) {
char *val;
STRDUP(val, value, return 1);
@@ -732,6 +736,7 @@ int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when)
hook_event.type = ALPM_EVENT_HOOK_RUN_START;
hook_event.name = hook->name;
+ hook_event.desc = hook->desc;
EVENT(handle, &hook_event);
if(_alpm_hook_run_hook(handle, hook) != 0 && hook->abort_on_fail) {
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 83939509..b19e645a 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -189,7 +189,8 @@ void cb_event(alpm_event_t *event)
alpm_event_hook_run_t *e = &event->hook_run;
int digits = number_length(e->total);
printf("(%*zu/%*zu) %s\n", digits, e->position,
- digits, e->total, e->name);
+ digits, e->total,
+ e->desc ? e->desc : e->name);
}
break;
case ALPM_EVENT_CHECKDEPS_START: