Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a label to identify the counted quantity
Matthew Seaman committed 11 years ago
commit 33eec32fa66e5a52b0ff35c979b35eea4bdf9a10
parent 0172451
4 files changed +34 -28
modified libpkg/pkg.h.in
@@ -1428,6 +1428,7 @@ struct pkg_event {
			int64_t total;
		} e_progress_tick;
		struct {
+
			const char *what;
			int64_t count;
			pkg_event_counter_t state;
		} e_counter;
modified libpkg/pkg_create.c
@@ -43,9 +43,9 @@
#define MAJOR_TICK	1000

static int pkg_create_from_dir(struct pkg *, const char *, struct packing *);
-
static void counter_init(int64_t *count);
-
static void counter_count(int64_t *count);
-
static void counter_end(int64_t *count);
+
static void counter_init(const char *what);
+
static void counter_count();
+
static void counter_end();

static int
pkg_create_from_dir(struct pkg *pkg, const char *root,
@@ -58,7 +58,6 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	struct stat	 st;
	char		 sha256[SHA256_DIGEST_LENGTH * 2 + 1];
	int64_t		 flatsize = 0;
-
	int64_t		 count;
	const char	*relocation;
	struct hardlinks *hardlinks = NULL;

@@ -75,7 +74,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	 * Get / compute size / checksum if not provided in the manifest
	 */

-
	counter_init(&count);
+
	counter_init("file size/checksum");

	while (pkg_files(pkg, &file) == EPKG_OK) {

@@ -111,10 +110,10 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
			}
		}

-
		counter_count(&count);
+
		counter_count();
	}

-
	counter_end(&count);
+
	counter_end();

	pkg->flatsize = flatsize;
	HASH_FREE(hardlinks, free);
@@ -140,7 +139,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		sbuf_delete(b);
	}

-
	counter_init(&count);
+
	counter_init("packaging files");

	while (pkg_files(pkg, &file) == EPKG_OK) {

@@ -151,12 +150,12 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		    file->uname, file->gname, file->perm);
		if (developer_mode && ret != EPKG_OK)
			return (ret);
-
		counter_count(&count);
+
		counter_count();
	}

-
	counter_end(&count);
+
	counter_end();

-
	counter_init(&count);
+
	counter_init("directories");

	while (pkg_dirs(pkg, &dir) == EPKG_OK) {
		snprintf(fpath, sizeof(fpath), "%s%s%s", root ? root : "",
@@ -166,10 +165,10 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		    dir->uname, dir->gname, dir->perm);
		if (developer_mode && ret != EPKG_OK)
			return (ret);
-
		counter_count(&count);
+
		counter_count();
	}

-
	counter_end(&count);
+
	counter_end();

	return (EPKG_OK);
}
@@ -419,31 +418,35 @@ pkg_create_installed(const char *outdir, pkg_formats format, struct pkg *pkg)
	return packing_finish(pkg_archive);
}

+
static int64_t	count;
+
static const char *what;
+

static void
-
counter_init(int64_t *count)
+
counter_init(const char *count_what)
{
-
	*count = 0;
-
	pkg_emit_counter(*count, PKG_EVENT_COUNTER_START);
+
	count = 0;
+
	what = count_what;
+
	pkg_emit_counter(what, count, PKG_EVENT_COUNTER_START);

	return;
}

static void
-
counter_count(int64_t *count)
+
counter_count()
{
-
	(*count)++;
+
	count++;

-
	if (*count % MAJOR_TICK == 0)
-
		pkg_emit_counter(*count, PKG_EVENT_COUNTER_MAJOR_TICK);
-
	else if (*count % MINOR_TICK == 0)
-
		pkg_emit_counter(*count, PKG_EVENT_COUNTER_MINOR_TICK);
+
	if (count % MAJOR_TICK == 0)
+
		pkg_emit_counter(what, count, PKG_EVENT_COUNTER_MAJOR_TICK);
+
	else if (count % MINOR_TICK == 0)
+
		pkg_emit_counter(what, count, PKG_EVENT_COUNTER_MINOR_TICK);

	return;
}

static void
-
counter_end(int64_t *count)
+
counter_end()
{
-
	pkg_emit_counter(*count, PKG_EVENT_COUNTER_END);
+
	pkg_emit_counter(what, count, PKG_EVENT_COUNTER_END);
	return;
}
modified libpkg/pkg_event.c
@@ -385,8 +385,9 @@ pipeevent(struct pkg_event *ev)
		break;
	case PKG_EVENT_COUNTER:
		sbuf_printf(msg, "{ \"type\": \"COUNTER\", "
-
		    "\"data\": %ld, \"state\": %s}",
-
		    ev->e_counter.count, counter_states[ev->e_counter.state]);
+
		    "\"what\": %s, \"data\": %ld, \"state\": %s}",
+
		    ev->e_counter.what, ev->e_counter.count,
+
		    counter_states[ev->e_counter.state]);
		break;
	case PKG_EVENT_BACKUP:
	case PKG_EVENT_RESTORE:
@@ -1015,11 +1016,12 @@ pkg_emit_progress_tick(int64_t current, int64_t total)
}

void
-
pkg_emit_counter(int64_t count, pkg_event_counter_t state)
+
pkg_emit_counter(const char *what, int64_t count, pkg_event_counter_t state)
{
	struct pkg_event ev;

	ev.type = PKG_EVENT_COUNTER;
+
	ev.e_counter.what  = what;
	ev.e_counter.count = count;
	ev.e_counter.state = state;

modified libpkg/private/event.h
@@ -70,7 +70,7 @@ int pkg_emit_query_select(const char *msg, const char **items, int ncnt, int def
void pkg_emit_progress_start(const char *fmt, ...);
void pkg_emit_progress_tick(int64_t current, int64_t total);

-
void pkg_emit_counter(int64_t count, pkg_event_counter_t state);
+
void pkg_emit_counter(const char *what, int64_t count, pkg_event_counter_t state);

void pkg_emit_add_deps_begin(struct pkg *p);
void pkg_emit_add_deps_finished(struct pkg *p);