[pacman-dev] [PATH] New Rg option

Xavier shiningxc at gmail.com
Tue Sep 11 09:48:18 EDT 2007


On Tue, Sep 11, 2007 at 12:04:22PM +0200, Nagy Gabor wrote:
> > Seems like the pacman_remove function in src/pacman/remove.c may be too basic
> > :
> > it first checks if the target is a group, otherwise it considers it as a
> > package.
> > It can't be both in the same time.
> > 
> > But I'm not sure yet what should be pacman's behavior in this case..
> 
> When I first tried to install or remove a group, I automatically tried with -Sg
> and -Rg. Unfortunately -Sg has a different meaning, but IMHO this way would be
> cleaner (for me), and -Rg would solve your problem. However, user should know
> what he wants to do... ;-)
> 

That's probably a good idea, I made a patch for it.
pacman -R xorg will only try to remove the xorg package,
pacman -Rg xorg will only try to remove the xorg group.


>From f22c3fa84ec2e46f1ff8b0967cd73b077f6d3b72 Mon Sep 17 00:00:00 2001
From: Chantry Xavier <shiningxc at gmail.com>
Date: Tue, 11 Sep 2007 15:22:16 +0200
Subject: [PATCH] pacman.c : add -Rg option for removing groups.

Signed-off-by: Chantry Xavier <shiningxc at gmail.com>
---
 doc/pacman.8        |    3 +++
 src/pacman/pacman.c |    1 +
 src/pacman/remove.c |   46 +++++++++++++++++++++++++++-------------------
 3 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/doc/pacman.8 b/doc/pacman.8
index 4825f4a..2908f75 100644
--- a/doc/pacman.8
+++ b/doc/pacman.8
@@ -179,6 +179,9 @@ Instructs pacman to ignore file backup designations.  Normally, when a file is
 removed from the system the database is checked to see if the file should be
 renamed with a .pacsave extension.
 .TP
+.B \-g, --groups
+Removes all the members for each package group specified.
+.TP
 .B \-s, --recursive
 Remove each target specified including all dependencies, provided that (A) they
 are not required by other packages; and (B) they were not explicitly installed
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index f62e588..e3073bc 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -93,6 +93,7 @@ static void usage(int op, char *myname)
 			printf("%s:\n", str_opt);
 			printf(_("  -c, --cascade        remove packages and all packages that depend on them\n"));
 			printf(_("  -d, --nodeps         skip dependency checks\n"));
+			printf(_("  -g, --groups         remove all members of a package group\n"));
 			printf(_("  -k, --dbonly         only remove database entry, do not remove files\n"));
 			printf(_("  -n, --nosave         remove configuration files as well\n"));
 			printf(_("  -s, --recursive      remove dependencies also (that won't break packages)\n"));
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index e60d3e8..cb71422 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -68,27 +68,35 @@ int pacman_remove(alpm_list_t *targets)
 		return(1);
 	}
 
-	/* If the target is a group, ask if its packages should be removed 
-	 * (the library can't remove groups for now)
-	 */
-	for(i = targets; i; i = alpm_list_next(i)) {
-		pmgrp_t *grp = alpm_db_readgrp(db_local, alpm_list_getdata(i));
-		if(grp) {
-			int all;
-			const alpm_list_t *p, *pkgnames = alpm_grp_get_pkgs(grp);
-
-			printf(_(":: group %s:\n"), alpm_grp_get_name(grp));
-			list_display("   ", pkgnames);
-			all = yesno(_("    Remove whole content? [Y/n] "));
-
-			for(p = pkgnames; p; p = alpm_list_next(p)) {
-				char *pkg = alpm_list_getdata(p);
-				if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), pkg, (char *)alpm_list_getdata(i))) {
-					finaltargs = alpm_list_add(finaltargs, strdup(pkg));
+	if(config->group) {
+		/* handle the targets as group since -g was specified */
+		for(i = targets; i; i = alpm_list_next(i)) {
+			pmgrp_t *grp = alpm_db_readgrp(db_local, alpm_list_getdata(i));
+			char *grpname = alpm_list_getdata(i);
+			if(grp) {
+				/* If the target is a group, ask if its packages should be removed 
+				 * (the library can't remove groups for now)
+				 */
+				int all;
+				const alpm_list_t *p, *pkgnames = alpm_grp_get_pkgs(grp);
+
+				printf(_(":: group %s:\n"), alpm_grp_get_name(grp));
+				list_display("   ", pkgnames);
+				all = yesno(_("    Remove whole content? [Y/n] "));
+
+				for(p = pkgnames; p; p = alpm_list_next(p)) {
+					char *pkg = alpm_list_getdata(p);
+					if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), pkg, grpname)) {
+						finaltargs = alpm_list_add(finaltargs, strdup(pkg));
+					}
 				}
+			} else {
+				printf(_(":: group %s not found\n"), grpname);
 			}
-		} else {
-			/* not a group, so add it to the final targets */
+		}
+	} else {
+		/* handle the targets as actual packages */
+		for(i = targets; i; i = alpm_list_next(i)) {
 			finaltargs = alpm_list_add(finaltargs, strdup(alpm_list_getdata(i)));
 		}
 	}
-- 
1.5.3





More information about the pacman-dev mailing list