Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Revert "Add interactive (-i) switch to pkg autoremove"
Baptiste Daroussin committed 13 years ago
commit 201349ec242385aa34b7d655ffee1bc93240d895
parent 47f80fc
4 files changed +19 -51
modified libpkg/pkg.h
@@ -852,12 +852,6 @@ void pkg_jobs_free(struct pkg_jobs *jobs);
int pkg_jobs_add(struct pkg_jobs *jobs, struct pkg *pkg);

/**
-
 * Remove a pkg from the jobs queue.
-
 * @return An error code.
-
 */
-
int pkg_jobs_rem(struct pkg_jobs *jobs, struct pkg *pkg);
-

-
/**
 * Returns true if there are no jobs.
 */
int pkg_jobs_is_empty(struct pkg_jobs *jobs);
modified libpkg/pkg_jobs.c
@@ -100,17 +100,6 @@ pkg_jobs_add(struct pkg_jobs *j, struct pkg *pkg)
}

int
-
pkg_jobs_rem(struct pkg_jobs *j, struct pkg *pkg)
-
{
-
	assert(j != NULL);
-
	assert(pkg != NULL);
-

-
	STAILQ_REMOVE(&j->jobs, pkg, pkg, next);
-

-
	return (EPKG_OK);
-
}
-

-
int
pkg_jobs_is_empty(struct pkg_jobs *j)
{
	assert(j != NULL);
modified pkg/autoremove.c
@@ -38,7 +38,7 @@
void
usage_autoremove(void)
{
-
	fprintf(stderr, "usage: pkg autoremove [-iyq]\n\n");
+
	fprintf(stderr, "usage: pkg autoremove [-yq]\n\n");
	fprintf(stderr, "For more information see 'pkg help autoremove'.\n");
}

@@ -55,13 +55,9 @@ exec_autoremove(int argc, char **argv)
	char size[7];
	int ch;
	bool yes = false;
-
	bool interactive = false;

-
	while ((ch = getopt(argc, argv, "iyq")) != -1) {
+
	while ((ch = getopt(argc, argv, "yq")) != -1) {
		switch (ch) {
-
		case 'i':
-
			interactive = true;
-
			break;
		case 'q':
			quiet = true;
			break;
@@ -103,10 +99,20 @@ exec_autoremove(int argc, char **argv)
	}

	while ((retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
+
		pkg_get(pkg, PKG_FLATSIZE, &flatsize, PKG_NEW_FLATSIZE, &newflatsize);
+
		oldsize += flatsize;
+
		newsize += newflatsize;
		pkg_jobs_add(jobs, pkg);
		pkg = NULL;
	}

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

	if (pkg_jobs_is_empty(jobs)) {
		printf("Nothing to do.\n");
		retcode = 0;
@@ -116,35 +122,16 @@ exec_autoremove(int argc, char **argv)
	pkg = NULL;
	if (!quiet) {
		printf("Packages to be autoremoved: \n");
-
		int torem = 1;
		while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
			const char *name, *version;
-
			pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version, PKG_FLATSIZE, &flatsize, PKG_NEW_FLATSIZE, &newflatsize);
-
			printf("\t%s-%s", name, version);
-

-
			if (interactive) {
-
				if (!(torem = query_yesno(" [y/N]: "))) {
-
					pkg_jobs_rem(jobs, pkg);
-
				}
-
			} else {
-
				puts(""); /* need a newline here */
-
			}
-

-

-
			if (torem) {
-
				oldsize += flatsize;
-
				newsize += newflatsize;
-
			}
+
			pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version);
+
			printf("\t%s-%s\n", name, version);
		}

-
		if (pkg_jobs_is_empty(jobs)) {
-
			printf("Nothing to do.\n");
-
			retcode = 0;
-
			goto cleanup;
-
		}
-

-
		humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
-
		printf("\nThe autoremoval will free %s\n", size);
+
		if (oldsize > newsize)
+
			printf("\nThe autoremoval will free %s\n", size);
+
		else
+
			printf("\nThe autoremoval will require %s more space\n", size);

		if (!yes)
			pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
modified pkg/pkg-autoremove.8
@@ -23,7 +23,7 @@
.Nd removes orphan packages
.Sh SYNOPSIS
.Nm
-
.Op Fl iyq
+
.Op Fl yq
.Sh DESCRIPTION
.Nm
is used for removing orphan packages, which were installed
@@ -32,8 +32,6 @@ during dependency resolution and are no longer needed.
The following options are supported by
.Nm :
.Bl -tag -width F1
-
.It Fl i
-
Interactively ask for a confirmation on every package.
.It Fl y
Assume yes when asked for confirmation before package autoremoval.
.It Fl q