Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
progress: fix progression and job count
Baptiste Daroussin committed 1 year ago
commit 777ce1f8bcd98fa20a3ea98d104cc168ba44e389
parent 2afad96
16 files changed +42 -40
modified libpkg/pkg.h.in
@@ -1502,6 +1502,10 @@ struct pkg_event {
			const char *name;
			bool cleanup;
		} e_trigger;
+
		struct {
+
			size_t total;
+
			size_t current;
+
		} e_action;
	};
};

modified libpkg/pkg_add.c
@@ -1424,8 +1424,6 @@ pkg_add_common(struct pkg_add_db *db, const char *path, unsigned flags,
		retcode = ret;
		goto cleanup;
	}
-
	if ((flags & PKG_ADD_SPLITTED_UPGRADE) == 0)
-
		pkg_emit_new_action();
	if ((flags & (PKG_ADD_UPGRADE | PKG_ADD_SPLITTED_UPGRADE)) !=
	    PKG_ADD_UPGRADE)
		pkg_emit_install_begin(pkg);
modified libpkg/pkg_delete.c
@@ -73,7 +73,6 @@ pkg_delete(struct pkg *pkg, struct pkg *rpkg, struct pkgdb *db, int flags,
	if (rpkg != NULL && pkgdb_ensure_loaded(db, rpkg, load_flags) != EPKG_OK)
		return (EPKG_FATAL);

-
	pkg_emit_new_action();
	pkg_emit_deinstall_begin(pkg);

	/* If the package is locked */
modified libpkg/pkg_event.c
@@ -1083,11 +1083,13 @@ pkg_emit_progress_tick(int64_t current, int64_t total)
}

void
-
pkg_emit_new_action(void)
+
pkg_emit_new_action(size_t current, size_t total)
{
	struct pkg_event ev;

	ev.type = PKG_EVENT_NEW_ACTION;
+
	ev.e_action.total = total;
+
	ev.e_action.current = current;

	pkg_emit_event(&ev);
}
modified libpkg/pkg_jobs.c
@@ -2090,6 +2090,8 @@ pkg_jobs_execute(struct pkg_jobs *j)
	struct pkg *p;
	int retcode = EPKG_FATAL;
	pkg_plugin_hook_t pre, post;
+
	size_t total_actions;
+
	size_t current_action = 0;

//j->triggers.cleanup = triggers_load(true);
	if (j->type == PKG_JOBS_INSTALL) {
@@ -2123,9 +2125,11 @@ pkg_jobs_execute(struct pkg_jobs *j)
	if (retcode != EPKG_OK)
		return (retcode);

+
	total_actions = tll_length(j->jobs);
	tll_foreach(j->jobs, _p) {
		struct pkg_solved *ps = _p->item;

+
		pkg_emit_new_action(++current_action, total_actions);
		switch (ps->type) {
		case PKG_SOLVED_DELETE:
			if ((j->flags & PKG_FLAG_FORCE) == 0) {
modified libpkg/private/event.h
@@ -134,7 +134,7 @@ void pkg_emit_extract_begin(struct pkg *p);
void pkg_emit_extract_finished(struct pkg *p);
void pkg_emit_delete_files_begin(struct pkg *p);
void pkg_emit_delete_files_finished(struct pkg *p);
-
void pkg_emit_new_action(void);
+
void pkg_emit_new_action(size_t current, size_t total);
void pkg_emit_message(const char *msg);
void pkg_emit_file_missing(struct pkg *p, struct pkg_file *f);
void pkg_register_cleanup_callback(void (*cleanup_cb)(void *data), void *data);
modified src/autoremove.c
@@ -50,7 +50,7 @@ exec_autoremove(int argc, char **argv)
	struct pkg_jobs *jobs = NULL;
	int retcode = EXIT_SUCCESS;
	int ch;
-
	nbactions = nbdone = 0;
+
	int nbactions = 0;
	pkg_flags f = PKG_FLAG_FORCE;
	bool rc = false;
	int lock_type = PKGDB_LOCK_ADVISORY;
modified src/check.c
@@ -256,6 +256,7 @@ exec_check(int argc, char **argv)
	int nbpkgs = 0;
	int i, processed, total = 0;
	int verbose = 0;
+
	int nbactions;

	struct option longopts[] = {
		{ "all",		no_argument,	NULL,	'a' },
@@ -360,7 +361,6 @@ exec_check(int argc, char **argv)
		return (EXIT_FAILURE);

	i = 0;
-
	nbdone = 0;
	do {
		/* XXX: This is really quirky, it would be cleaner to pass
		 * in multiple matches and only run this top-loop once. */
@@ -397,7 +397,6 @@ exec_check(int argc, char **argv)
				if (!verbose)
					progressbar_tick(processed, total);
				else {
-
					++nbdone;
					job_status_begin(msg);
					pkg_fprintf(msg->fp, "Checking %n-%v:",
					    pkg, pkg);
modified src/delete.c
@@ -59,6 +59,7 @@ exec_delete(int argc, char **argv)
	int		 i;
	int		 lock_type = PKGDB_LOCK_ADVISORY;
	int		 locked_pkgs = 0;
+
	int		 nbactions = 0;

	struct option longopts[] = {
		{ "all",			no_argument,	NULL,	'a' },
@@ -75,7 +76,6 @@ exec_delete(int argc, char **argv)
		{ NULL,				0,		NULL,	0   },
	};

-
	nbactions = nbdone = 0;

	while ((ch = getopt_long(argc, argv, "+aCDfginqRxy", longopts, NULL)) != -1) {
		switch (ch) {
modified src/event.c
@@ -86,6 +86,8 @@ static time_t begin = 0;
static int add_deps_depth;
static tll(struct cleanup *) cleanup_list = tll_init();
static bool signal_handler_installed = false;
+
static size_t nbactions = 0;
+
static size_t nbdone = 0;

/* units for format_size */
static const char *unit_SI[] = { " ", "k", "M", "G", "T", };
@@ -173,7 +175,7 @@ job_status_begin(xstring *msg)
	}

	if ((nbtodl > 0 || nbactions > 0) && nbdone > 0)
-
		fprintf(msg->fp, "[%d/%d] ", nbdone, (nbtodl) ? nbtodl : nbactions);
+
		fprintf(msg->fp, "[%zu/%zu] ", nbdone, (nbtodl) ? nbtodl : nbactions);
	if (nbtodl > 0 && nbtodl == nbdone) {
		nbtodl = 0;
		nbdone = 0;
@@ -674,7 +676,8 @@ event_callback(void *data, struct pkg_event *ev)
		fprintf(msg_buf->fp, "Restoring");
		break;
	case PKG_EVENT_NEW_ACTION:
-
		nbdone++;
+
		nbactions = ev->e_action.total;
+
		nbdone = ev->e_action.current;
		break;
	case PKG_EVENT_MESSAGE:
		if (messages == NULL)
modified src/globals.c
@@ -31,8 +31,6 @@ int case_sensitive; /* Case sensitive queries */
int force; /* Forced operation */
int quiet; /* Silent output */
int newpkgversion; /* New package version is available */
-
int nbactions;
-
int nbdone;
int nbtodl;

void
@@ -46,8 +44,6 @@ set_globals(void)
	force = 0;
	quiet = 0;
	newpkgversion = 0;
-
	nbactions = 0;
-
	nbdone = 0;
	nbtodl = 0;
}

modified src/install.c
@@ -63,6 +63,7 @@ exec_install(int argc, char **argv)
	int		 mode, repo_type;
	int		 done = 0;
	int		 lock_type = PKGDB_LOCK_ADVISORY;
+
	int		 nbactions = 0;
	bool		 rc = true;
	bool		 local_only = false;
	match_t		 match = MATCH_EXACT;
@@ -89,8 +90,6 @@ exec_install(int argc, char **argv)
		{ NULL,			0,			NULL,	0   },
	};

-
	nbactions = nbdone = 0;
-

	if (STREQ(argv[0], "add")) {
		auto_update = false;
		local_only = true;
modified src/pkgcli.h
@@ -20,8 +20,6 @@
#define ll_foreach(head, el) for (el=head; el != NULL; el = (el)->next)

extern bool quiet;
-
extern int nbactions;
-
extern int nbdone;
extern bool newpkgversion;
extern int nbtodl;

modified src/upgrade.c
@@ -246,6 +246,7 @@ exec_upgrade(int argc, char **argv)
	int		 lock_type = PKGDB_LOCK_ADVISORY;
	match_t		 match = MATCH_EXACT;
	int		 done = 0;
+
	int		 nbactions = 0;
	bool	rc = true;
	pkg_flags	 f = PKG_FLAG_NONE | PKG_FLAG_PKG_VERSION_TEST;
	c_charv_t	reponames;
@@ -267,7 +268,6 @@ exec_upgrade(int argc, char **argv)
		{ NULL,			0,			NULL,	0   },
	};

-
	nbactions = nbdone = 0;
	vec_init(&reponames);

	while ((ch = getopt_long(argc, argv, "+CfFgiInqr:Uxyv", longopts, NULL)) != -1) {
modified tests/frontend/conflicts-multirepo.sh
@@ -361,12 +361,12 @@ Installed packages to be UPGRADED:
	test2: 1 -> 1.1 [local2]

Number of packages to be upgraded: 2
-
${JAILED}[1/2] Deinstalling test2-1...
-
${JAILED}[1/2] Deleting files for test2-1:  done
-
${JAILED}[2/2] Upgrading test from 1 to 1.1...
-
${JAILED}[2/2] Extracting test-1.1:  done
-
${JAILED}[2/2] Installing test2-1.1...
-
${JAILED}[2/2] Extracting test2-1.1:  done
+
${JAILED}[1/3] Deinstalling test2-1...
+
${JAILED}[1/3] Deleting files for test2-1:  done
+
${JAILED}[2/3] Upgrading test from 1 to 1.1...
+
${JAILED}[2/3] Extracting test-1.1:  done
+
${JAILED}[3/3] Installing test2-1.1...
+
${JAILED}[3/3] Extracting test2-1.1:  done
"
	atf_check \
		-o inline:"${OUTPUT}" \
modified tests/frontend/conflicts.sh
@@ -150,12 +150,12 @@ Installed packages to be REMOVED:
Number of packages to be removed: 1
Number of packages to be installed: 1
Number of packages to be upgraded: 1
-
[1/3] Deinstalling foo-1.0...
-
[2/3] Deinstalling bar-1.0...
-
[2/3] Deleting files for bar-1.0:  done
-
[3/3] Installing bar1-1.1...
-
[3/3] Extracting bar1-1.1:  done
-
[3/3] Installing foo-1.0_1...
+
[1/4] Deinstalling foo-1.0...
+
[2/4] Deinstalling bar-1.0...
+
[2/4] Deleting files for bar-1.0:  done
+
[3/4] Installing bar1-1.1...
+
[3/4] Extracting bar1-1.1:  done
+
[4/4] Installing foo-1.0_1...
"

	atf_check \
@@ -353,14 +353,14 @@ Installed packages to be REMOVED:
Number of packages to be removed: 2
Number of packages to be installed: 2
Number of packages to be upgraded: 1
-
[1/5] Deinstalling other-1.0...
-
[2/5] Deinstalling foo-1.0...
-
[3/5] Deinstalling bar-1.0...
-
[3/5] Deleting files for bar-1.0:  done
-
[4/5] Installing bar1-1.1...
-
[4/5] Extracting bar1-1.1:  done
-
[4/5] Installing foo-1.0_1...
-
[5/5] Installing arp-1.0_1...
+
[1/6] Deinstalling other-1.0...
+
[2/6] Deinstalling foo-1.0...
+
[3/6] Deinstalling bar-1.0...
+
[3/6] Deleting files for bar-1.0:  done
+
[4/6] Installing bar1-1.1...
+
[4/6] Extracting bar1-1.1:  done
+
[5/6] Installing foo-1.0_1...
+
[6/6] Installing arp-1.0_1...
"

	atf_check \