Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Factorise a bit jobs summary printing in 'install' and 'upgrade'
Marin Atanasov Nikolov committed 14 years ago
commit a48a4bee006d743d4a07d25e9ed869c1ce405907
parent a29d6cd
4 files changed +68 -86
modified pkg/install.c
@@ -59,9 +59,7 @@ exec_install(int argc, char **argv)
	int retcode = 1;
	int ch;
	bool yes = false;
-
	int64_t dlsize = 0;
-
	int64_t oldsize = 0, newsize = 0;
-
	char size[7];
+

	match_t match = MATCH_EXACT;
	bool force = false;

@@ -129,45 +127,7 @@ exec_install(int argc, char **argv)
	/* print a summary before applying the jobs */
	pkg = NULL;
	if (!quiet) {
-
		printf("The following packages will be installed:\n");
-

-
		while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
-
			const char *name, *version, *newversion;
-
			int64_t flatsize, newflatsize, pkgsize;
-
			pkg_get(pkg, PKG_NEWVERSION, &newversion, PKG_NAME, &name,
-
					PKG_VERSION, &version, PKG_FLATSIZE, &flatsize,
-
					PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &pkgsize);
-
			dlsize += pkgsize;
-
			if (newversion != NULL) {
-
				switch (pkg_version_cmp(version, newversion)) {
-
					case 1:
-
						printf("\tDowngrading %s: %s -> %s\n", name, version, newversion);
-
						break;
-
					case 0:
-
						printf("\tReinstalling %s-%s\n", name, version);
-
						break;
-
					case -1:
-
						printf("\tUpgrading %s: %s -> %s\n", name, version, newversion);
-
						break;
-
				}
-
				oldsize += flatsize;
-
				newsize += newflatsize;
-
			} else {
-
				newsize += flatsize;
-
				printf("\tInstalling %s: %s\n", name, version);
-
			}
-
		}
-

-
		if (oldsize > newsize) {
-
			newsize *= -1;
-
			humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0);
-
			printf("\nthe installation will save %s\n", size);
-
		} else {
-
			humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
-
			printf("\nthe installation will require %s more space\n", size);
-
		}
-
		humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
-
		printf("%s to be downloaded\n", size);
+
		print_jobs_summary(jobs, PKG_JOBS_INSTALL, "The following packages will be installed:\n");

		if (!yes)
			pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
modified pkg/pkgcli.h
@@ -148,6 +148,7 @@ void usage_which(void);
bool query_yesno(const char *msg, ...);
int print_info(struct pkg * const pkg, unsigned int opt);
char *absolutepath(const char *src, char *dest, size_t dest_len);
+
void print_jobs_summary(struct pkg_jobs *j, pkg_jobs_t type, const char *msg, ...);

int event_callback(void *data, struct pkg_event *ev);

modified pkg/upgrade.c
@@ -50,9 +50,6 @@ exec_upgrade(int argc, char **argv)
	struct pkg_jobs *jobs = NULL;
	const char *reponame = NULL;
	int retcode = 1;
-
	int64_t oldsize = 0, newsize = 0;
-
	int64_t dlsize = 0;
-
	char size[7];
	int ch;
	bool yes = false;
	bool all = false;
@@ -117,45 +114,7 @@ exec_upgrade(int argc, char **argv)

	pkg = NULL;
	if (!quiet) {
-
		printf("The following packages will be upgraded: \n");
-
		while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
-
			const char *newversion, *name, *version;
-
			int64_t newpkgsize, flatsize, newflatsize;
-

-
			pkg_get(pkg, PKG_NEWVERSION, &newversion, PKG_NAME, &name, PKG_VERSION, &version,
-
					PKG_NEW_PKGSIZE, &newpkgsize, PKG_NEW_FLATSIZE, &newflatsize,
-
					PKG_FLATSIZE, &flatsize);
-
			dlsize += newpkgsize;
-
			if (newversion != NULL) {
-
				switch (pkg_version_cmp(version, newversion)) {
-
					case 1:
-
						printf("\tDowngrading %s: %s -> %s\n", name, version, newversion);
-
						break;
-
					case 0:
-
						printf("\tReinstalling %s-%s\n", name, version);
-
						break;
-
					case -1:
-
						printf("\tUpgrading %s: %s -> %s\n", name, version, newversion);
-
						break;
-
				}
-
				oldsize += flatsize;
-
				newsize += newflatsize;
-
			} else {
-
				newsize += flatsize;
-
				printf("\tInstalling %s: %s\n", name, version);
-
			}
-
		}
-

-
		if (oldsize > newsize) {
-
			newsize *= -1;
-
			humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0);
-
			printf("\nthe upgrade will save %s\n", size);
-
		} else {
-
			humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
-
			printf("\nthe upgrade will require %s more space\n", size);
-
		}
-
		humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
-
		printf("%s to be downloaded\n", size);
+
		print_jobs_summary(jobs, PKG_JOBS_INSTALL, "The following packages will be upgraded:\n");

		if (!yes)
			pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
modified pkg/utils.c
@@ -47,7 +47,6 @@ query_yesno(const char *msg, ...)
	vprintf(msg, ap);
	va_end(ap);

-

	c = getchar();
	if (c == 'y' || c == 'Y')
		r = true;
@@ -128,7 +127,6 @@ absolutepath(const char *src, char *dest, size_t dest_len) {
	return &dest[0];
}

-

int
print_info(struct pkg * const pkg, unsigned int opt)
{
@@ -288,3 +286,67 @@ print_info(struct pkg * const pkg, unsigned int opt)

        return (0);
}
+

+
void
+
print_jobs_summary(struct pkg_jobs *jobs, pkg_jobs_t type, const char *msg, ...)
+
{
+
	struct pkg *pkg = NULL;
+
	const char *name, *version, *newversion;
+
	int64_t dlsize, oldsize, newsize;
+
	int64_t flatsize, newflatsize, pkgsize;
+
	char size[7];
+
	va_list ap;
+

+
	va_start(ap, msg);
+
	vprintf(msg, ap);
+
	va_end(ap);
+

+
	dlsize = oldsize = newsize = 0;
+
	flatsize = newflatsize = pkgsize = 0;
+
	name = version = newversion = NULL;
+
	
+
	while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
+
		pkg_get(pkg, PKG_NEWVERSION, &newversion, PKG_NAME, &name,
+
			PKG_VERSION, &version, PKG_FLATSIZE, &flatsize,
+
			PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &pkgsize);
+

+
		dlsize += pkgsize;
+

+
		/* Install/Upgrade */
+
		if (type == PKG_JOBS_INSTALL) {
+
			if (newversion != NULL) {
+
				switch (pkg_version_cmp(version, newversion)) {
+
				case 1:
+
					printf("\tDowngrading %s: %s -> %s\n", name, version, newversion);
+
					break;
+
				case 0:
+
					printf("\tReinstalling %s-%s\n", name, version);
+
					break;
+
				case -1:
+
					printf("\tUpgrading %s: %s -> %s\n", name, version, newversion);
+
					break;
+
				}
+
				oldsize += flatsize;
+
				newsize += newflatsize;
+
			} else {
+
				newsize += flatsize;
+
				printf("\tInstalling %s: %s\n", name, version);
+
			}
+
		}
+

+
		/* Delete */
+

+
		/* Fetch */
+
	}
+

+
	if (oldsize > newsize) {
+
		newsize *= -1;
+
		humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0);
+
		printf("\nthe installation will save %s\n", size);
+
	} else {
+
		humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
+
		printf("\nthe installation will require %s more space\n", size);
+
	}
+
	humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
+
	printf("%s to be downloaded\n", size);
+
}