Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge pull request #357 from gahr/master
Baptiste Daroussin committed 13 years ago
commit 5854e3688bd1aa03799565a29ee3102bf493346b
parent 7bb30c4
4 files changed +51 -19
modified libpkg/pkg.h
@@ -852,6 +852,12 @@ 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,6 +100,17 @@ 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 [-yq]\n\n");
+
	fprintf(stderr, "usage: pkg autoremove [-iyq]\n\n");
	fprintf(stderr, "For more information see 'pkg help autoremove'.\n");
}

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

-
	while ((ch = getopt(argc, argv, "yq")) != -1) {
+
	while ((ch = getopt(argc, argv, "iyq")) != -1) {
		switch (ch) {
+
		case 'i':
+
			interactive = true;
+
			break;
		case 'q':
			quiet = true;
			break;
@@ -99,20 +103,10 @@ 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;
@@ -122,16 +116,35 @@ 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);
-
			printf("\t%s-%s\n", 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;
+
			}
		}

-
		if (oldsize > newsize)
-
			printf("\nThe autoremoval will free %s\n", size);
-
		else
-
			printf("\nThe autoremoval will require %s more space\n", size);
+
		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 (!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 yq
+
.Op Fl iyq
.Sh DESCRIPTION
.Nm
is used for removing orphan packages, which were installed
@@ -32,6 +32,8 @@ 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