Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use the pre-existing progress bars rather than rolling our own
Matthew Seaman committed 11 years ago
commit 284f9dd45e60fa7d8b2869e9da85b21278987e6e
parent 2584a9f
1 file changed +31 -13
modified libpkg/pkg_create.c
@@ -39,11 +39,10 @@
#include "private/event.h"
#include "private/pkg.h"

-
#define MINOR_TICK	100
-
#define MAJOR_TICK	1000
+
#define TICK	100

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

@@ -58,6 +57,7 @@ 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		 nfiles;
	const char	*relocation;
	struct hardlinks *hardlinks = NULL;

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

-
	counter_init("file sizes/checksums");
+
	nfiles = HASH_COUNT(pkg->files);
+
	counter_init("file sizes/checksums", nfiles);

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

@@ -139,7 +140,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		sbuf_delete(b);
	}

-
	counter_init("packing files");
+
	counter_init("packing files", nfiles);

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

@@ -155,7 +156,8 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,

	counter_end();

-
	counter_init("packing directories");
+
	nfiles = HASH_COUNT(pkg->dirs);
+
	counter_init("packing directories", nfiles);

	while (pkg_dirs(pkg, &dir) == EPKG_OK) {
		snprintf(fpath, sizeof(fpath), "%s%s%s", root ? root : "",
@@ -419,14 +421,32 @@ pkg_create_installed(const char *outdir, pkg_formats format, struct pkg *pkg)
}

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

+
static int magnitude(int64_t num)
+
{
+
	int oom;
+

+
	if (num == 0)
+
		return (1);
+
	if (num < 0)
+
		num = -num;
+

+
	for (oom = 1; num >= 10; oom++)
+
		num /= 10;
+

+
	return (oom);
+
}
+

static void
-
counter_init(const char *count_what)
+
counter_init(const char *count_what, int64_t max)
{
	count = 0;
	what = count_what;
-
	pkg_emit_counter(what, count, PKG_EVENT_COUNTER_START);
+
	maxcount = max;
+
	pkg_emit_progress_start("%-20s%*s[%ld]", what,
+
	    6 - magnitude(maxcount), " ", maxcount);

	return;
}
@@ -436,10 +456,8 @@ counter_count()
{
	count++;

-
	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);
+
	if (count % TICK == 0)
+
		pkg_emit_progress_tick(count, maxcount);

	return;
}
@@ -447,6 +465,6 @@ counter_count()
static void
counter_end()
{
-
	pkg_emit_counter(what, count, PKG_EVENT_COUNTER_END);
+
	pkg_emit_progress_tick(count, maxcount);
	return;
}