mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 07:48:50 -05:00
Show progress processing hooks
Introduces the ALPM_EVENT_HOOK_RUN_{START,DONE} events that are triggered at the start and end of running an individual hook. Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
8d3bd4ec13
commit
760bea5432
@ -461,7 +461,11 @@ typedef enum _alpm_event_type_t {
|
||||
/** Processing hooks will be started. */
|
||||
ALPM_EVENT_HOOK_START,
|
||||
/** Processing hooks is finished. */
|
||||
ALPM_EVENT_HOOK_DONE
|
||||
ALPM_EVENT_HOOK_DONE,
|
||||
/** A hook is starting */
|
||||
ALPM_EVENT_HOOK_RUN_START,
|
||||
/** A hook has finnished runnning */
|
||||
ALPM_EVENT_HOOK_RUN_DONE
|
||||
} alpm_event_type_t;
|
||||
|
||||
typedef struct _alpm_event_any_t {
|
||||
@ -559,6 +563,17 @@ typedef struct _alpm_event_hook_t {
|
||||
alpm_hook_when_t when;
|
||||
} alpm_event_hook_t;
|
||||
|
||||
typedef struct _alpm_event_hook_run_t {
|
||||
/** Type of event.*/
|
||||
alpm_event_type_t type;
|
||||
/** Name of hook */
|
||||
const char *name;
|
||||
/** position of hook being run */
|
||||
size_t position;
|
||||
/** total hooks being run */
|
||||
size_t total;
|
||||
} alpm_event_hook_run_t;
|
||||
|
||||
/** Events.
|
||||
* This is an union passed to the callback, that allows the frontend to know
|
||||
* which type of event was triggered (via type). It is then possible to
|
||||
@ -576,6 +591,7 @@ typedef union _alpm_event_t {
|
||||
alpm_event_pacnew_created_t pacnew_created;
|
||||
alpm_event_pacsave_created_t pacsave_created;
|
||||
alpm_event_hook_t hook;
|
||||
alpm_event_hook_run_t hook_run;
|
||||
} alpm_event_t;
|
||||
|
||||
/** Event callback. */
|
||||
|
@ -611,9 +611,10 @@ static int _alpm_hook_run_hook(alpm_handle_t *handle, struct _alpm_hook_t *hook)
|
||||
int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when)
|
||||
{
|
||||
alpm_event_hook_t event = { .when = when };
|
||||
alpm_event_hook_run_t hook_event;
|
||||
alpm_list_t *i, *hooks = NULL, *hooks_triggered = NULL;
|
||||
const char *suffix = ".hook";
|
||||
size_t suflen = strlen(suffix);
|
||||
size_t suflen = strlen(suffix), triggered = 0;
|
||||
int ret = 0;
|
||||
|
||||
for(i = alpm_list_last(handle->hookdirs); i; i = alpm_list_previous(i)) {
|
||||
@ -714,6 +715,7 @@ int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when)
|
||||
struct _alpm_hook_t *hook = i->data;
|
||||
if(hook && hook->when == when && _alpm_hook_triggered(handle, hook)) {
|
||||
hooks_triggered = alpm_list_add(hooks_triggered, hook);
|
||||
triggered++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -721,12 +723,23 @@ int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when)
|
||||
event.type = ALPM_EVENT_HOOK_START;
|
||||
EVENT(handle, &event);
|
||||
|
||||
for(i = hooks_triggered; i; i = i->next) {
|
||||
hook_event.position = 1;
|
||||
hook_event.total = triggered;
|
||||
|
||||
for(i = hooks_triggered; i; i = i->next, hook_event.position++) {
|
||||
struct _alpm_hook_t *hook = i->data;
|
||||
_alpm_log(handle, ALPM_LOG_DEBUG, "running hook %s\n", hook->name);
|
||||
|
||||
hook_event.type = ALPM_EVENT_HOOK_RUN_START;
|
||||
hook_event.name = hook->name;
|
||||
EVENT(handle, &hook_event);
|
||||
|
||||
if(_alpm_hook_run_hook(handle, hook) != 0 && hook->abort_on_fail) {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
hook_event.type = ALPM_EVENT_HOOK_RUN_DONE;
|
||||
EVENT(handle, &hook_event);
|
||||
}
|
||||
|
||||
alpm_list_free(hooks_triggered);
|
||||
|
@ -160,6 +160,16 @@ static void fill_progress(const int bar_percent, const int disp_percent,
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static int number_length(size_t n)
|
||||
{
|
||||
int digits = 1;
|
||||
while((n /= 10)) {
|
||||
++digits;
|
||||
}
|
||||
|
||||
return digits;
|
||||
}
|
||||
|
||||
/* callback to handle messages/notifications from libalpm transactions */
|
||||
void cb_event(alpm_event_t *event)
|
||||
{
|
||||
@ -174,6 +184,14 @@ void cb_event(alpm_event_t *event)
|
||||
colon_printf(_("Running post-transaction hooks...\n"));
|
||||
}
|
||||
break;
|
||||
case ALPM_EVENT_HOOK_RUN_START:
|
||||
{
|
||||
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);
|
||||
}
|
||||
break;
|
||||
case ALPM_EVENT_CHECKDEPS_START:
|
||||
printf(_("checking dependencies...\n"));
|
||||
break;
|
||||
@ -341,6 +359,7 @@ void cb_event(alpm_event_t *event)
|
||||
case ALPM_EVENT_RETRIEVE_DONE:
|
||||
case ALPM_EVENT_RETRIEVE_FAILED:
|
||||
case ALPM_EVENT_HOOK_DONE:
|
||||
case ALPM_EVENT_HOOK_RUN_DONE:
|
||||
/* we can safely ignore those as well */
|
||||
case ALPM_EVENT_PKGDOWNLOAD_START:
|
||||
case ALPM_EVENT_PKGDOWNLOAD_DONE:
|
||||
@ -481,7 +500,6 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
|
||||
/* size of line to allocate for text printing (e.g. not progressbar) */
|
||||
int infolen;
|
||||
int digits, textlen;
|
||||
size_t tmp;
|
||||
char *opr = NULL;
|
||||
/* used for wide character width determination and printing */
|
||||
int len, wclen, wcwid, padwid;
|
||||
@ -557,11 +575,8 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
|
||||
}
|
||||
|
||||
/* find # of digits in package counts to scale output */
|
||||
digits = 1;
|
||||
tmp = howmany;
|
||||
while((tmp /= 10)) {
|
||||
++digits;
|
||||
}
|
||||
digits = number_length(howmany);
|
||||
|
||||
/* determine room left for non-digits text [not ( 1/12) part] */
|
||||
textlen = infolen - 3 /* (/) */ - (2 * digits) - 1 /* space */;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user