Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Factorise a bit the jobs summary printing in 'pkg delete'
Marin Atanasov Nikolov committed 14 years ago
commit 8fb798d3d606b8c242b358e211ef0d69f7c6f63f
parent a48a4be
2 files changed +49 -38
modified pkg/delete.c
@@ -58,8 +58,6 @@ exec_delete(int argc, char **argv)
	bool yes = false;
	int retcode = 1;
	int recursive = 0;
-
	int64_t oldsize = 0, newsize = 0;
-
	char size[7];

	while ((ch = getopt(argc, argv, "agxXfyr")) != -1) {
		switch (ch) {
@@ -119,10 +117,6 @@ exec_delete(int argc, char **argv)
		goto cleanup;

	while (pkgdb_it_next(it, &pkg, flags) == EPKG_OK) {
-
		int64_t flatsize, newflatsize;
-
		pkg_get(pkg, PKG_FLATSIZE, &flatsize, PKG_NEW_FLATSIZE, &newflatsize);
-
		oldsize += flatsize;
-
		newsize += newflatsize;
		pkg_jobs_add(jobs, pkg);
		pkg = NULL;
	}
@@ -140,28 +134,9 @@ exec_delete(int argc, char **argv)
		goto cleanup;
	}

-
	if (oldsize > newsize) {
-
		newsize *= -1;
-
		humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0);
-
	}
-
	else if (newsize > oldsize) {
-
		humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
-
	}
-

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

-
			pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version);
-
			printf("\t%s-%s\n", name, version);
-
		}
-

-
		if (oldsize > newsize)
-
			printf("\nThe deinstallation will save %s\n", size);
-
		else if (newsize > oldsize)
-
			printf("\nThe deinstallation will require %s more space\n", size);
+
		print_jobs_summary(jobs, PKG_JOBS_DEINSTALL, "The following packages will be deinstalled:\n");

		if (!yes)
			pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
modified pkg/utils.c
@@ -310,10 +310,11 @@ print_jobs_summary(struct pkg_jobs *jobs, pkg_jobs_t type, const char *msg, ...)
			PKG_VERSION, &version, PKG_FLATSIZE, &flatsize,
			PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &pkgsize);

-
		dlsize += pkgsize;
+
		switch (type) {
+
		case PKG_JOBS_INSTALL:
+
		case PKG_JOBS_UPGRADE:
+
			dlsize += pkgsize;

-
		/* Install/Upgrade */
-
		if (type == PKG_JOBS_INSTALL) {
			if (newversion != NULL) {
				switch (pkg_version_cmp(version, newversion)) {
				case 1:
@@ -332,21 +333,56 @@ print_jobs_summary(struct pkg_jobs *jobs, pkg_jobs_t type, const char *msg, ...)
				newsize += flatsize;
				printf("\tInstalling %s: %s\n", name, version);
			}
+
			break;
+
		case PKG_JOBS_DEINSTALL:
+
			oldsize += flatsize;
+
			newsize += newflatsize;
+
			
+
			printf("\t%s-%s\n", name, version);
+
			break;
+
		case PKG_JOBS_FETCH:
+
			dlsize += pkgsize;
+

+
			printf("\t%s-%s\n", name, version);
+
			break;
		}
-

-
		/* 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 {
+

+
		switch (type) {
+
		case PKG_JOBS_INSTALL:
+
		case PKG_JOBS_UPGRADE:
+
			printf("\nThe installation will save %s\n", size);
+
			break;
+
		case PKG_JOBS_DEINSTALL:
+
			printf("\nThe deinstallation will save %s\n", size);
+
			break;
+
		case PKG_JOBS_FETCH:
+
			/* nothing to report here */
+
			break;
+
		}
+
	} else if (newsize > oldsize) {
		humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
-
		printf("\nthe installation will require %s more space\n", size);
+

+
		switch (type) {
+
		case PKG_JOBS_INSTALL:
+
		case PKG_JOBS_UPGRADE:
+
			printf("\nThe installation will require %s more space\n", size);
+
			break;
+
		case PKG_JOBS_DEINSTALL:
+
			printf("\nThe deinstallation will require %s more space\n", size);
+
			break;
+
		case PKG_JOBS_FETCH:
+
			/* nothing to report here */
+
			break;
+
		}
+
	}
+

+
	if ((type == PKG_JOBS_INSTALL) || (type == PKG_JOBS_FETCH)) {
+
		humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
+
		printf("%s to be downloaded\n", size);
	}
-
	humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
-
	printf("%s to be downloaded\n", size);
}