Skip to content

Commit

Permalink
Use events to show install progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaffaye committed Jul 16, 2011
1 parent 0f9e6ee commit 018655a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion libpkg/pkg.h
Expand Up @@ -616,6 +616,7 @@ int pkg_script_run(struct pkg *, pkg_script_t type);
typedef enum {
/* informational */
PKG_EVENT_INSTALL_BEGIN = 0,
PKG_EVENT_INSTALL_FINISHED,
PKG_EVENT_FETCHING,
/* errors */
PKG_EVENT_ERROR,
Expand Down Expand Up @@ -651,7 +652,10 @@ struct pkg_event {
} e_already_installed;
struct {
struct pkg *pkg;
} e_begin_install;
} e_install_begin;
struct {
struct pkg *pkg;
} e_install_finished;
struct {
struct pkg *pkg;
struct pkg_dep *dep;
Expand Down
2 changes: 2 additions & 0 deletions libpkg/pkg_add.c
Expand Up @@ -187,6 +187,8 @@ pkg_add(struct pkgdb *db, const char *path)
*/
pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL);

EMIT_INSTALL_FINISHED(pkg);

cleanup_reg:
pkgdb_register_finale(db, retcode);

Expand Down
9 changes: 8 additions & 1 deletion libpkg/pkg_event.h
Expand Up @@ -47,7 +47,14 @@
#define EMIT_INSTALL_BEGIN(p) \
_EV_START; \
ev.type = PKG_EVENT_INSTALL_BEGIN; \
ev.e_begin_install.pkg = p; \
ev.e_install_begin.pkg = p; \
_EV_EMIT; \
_EV_END

#define EMIT_INSTALL_FINISHED(p) \
_EV_START; \
ev.type = PKG_EVENT_INSTALL_FINISHED; \
ev.e_install_finished.pkg = p; \
_EV_EMIT; \
_EV_END

Expand Down
10 changes: 10 additions & 0 deletions pkg/event.c
Expand Up @@ -7,6 +7,7 @@ int
event_callback(void *data __unused, struct pkg_event *ev)
{
unsigned int percent;
const char *message;

switch(ev->type) {
case PKG_EVENT_ERRNO:
Expand All @@ -23,6 +24,15 @@ event_callback(void *data __unused, struct pkg_event *ev)
fflush(stdout);
break;
case PKG_EVENT_INSTALL_BEGIN:
printf("Installing %s-%s...",
pkg_get(ev->e_install_begin.pkg, PKG_NAME),
pkg_get(ev->e_install_begin.pkg, PKG_VERSION));
break;
case PKG_EVENT_INSTALL_FINISHED:
printf(" done\n");
message = pkg_get(ev->e_install_finished.pkg, PKG_MESSAGE);
if (message != NULL && message[0] != '\0')
printf("%s\n", message);
break;
default:
break;
Expand Down

0 comments on commit 018655a

Please sign in to comment.