Subject: rm.diff 4
To: None <tech-userlevel@netbsd.org>
From: Jason R. Fink <jrf@adresearch.com>
List: tech-userlevel
Date: 01/09/2003 14:58:58
--ZGiS0Q5IWpPtfppv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Here is one I tested with unionfs.
Thanks to Enami for picking out some errors.

	j

-- 
J Fink http://pyxis.homeunix.net/~jrf/
NetBSD Developer http://www.netbsd.org/
Senior Sysadmin/Programmer http://www.ipsos.com/

--ZGiS0Q5IWpPtfppv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="rm.diff"

Index: rm.1
===================================================================
RCS file: /cvsroot/src/bin/rm/rm.1,v
retrieving revision 1.14
diff -u -r1.14 rm.1
--- rm.1	2002/05/02 13:14:23	1.14
+++ rm.1	2003/01/09 19:55:41
@@ -36,7 +36,7 @@
 .\"
 .\"	@(#)rm.1	8.5 (Berkeley) 12/5/94
 .\"
-.Dd December 5, 1994
+.Dd January 8, 2003
 .Dt RM 1
 .Os
 .Sh NAME
@@ -45,7 +45,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl f | Fl i
-.Op Fl dPRrW
+.Op Fl dPRrvW
 .Ar
 .Sh DESCRIPTION
 The
@@ -101,6 +101,10 @@
 .It Fl r
 Equivalent to
 .Fl R .
+.It Fl v
+Cause
+.Nm
+to be verbose, showing files as they are processed.
 .It Fl W
 Attempts to undelete the named files.
 Currently, this option can only be used to recover
@@ -155,3 +159,8 @@
 utility is expected to be
 .St -p1003.2
 compatible.
+.Pp
+The
+.Fl v
+option is an extension to
+.St -p1003.2 .
Index: rm.c
===================================================================
RCS file: /cvsroot/src/bin/rm/rm.c,v
retrieving revision 1.31
diff -u -r1.31 rm.c
--- rm.c	2002/11/05 04:49:05	1.31
+++ rm.c	2003/01/09 19:55:41
@@ -62,7 +62,7 @@
 #include <string.h>
 #include <unistd.h>
 
-int dflag, eval, fflag, iflag, Pflag ,stdin_ok, Wflag;
+int dflag, eval, fflag, iflag, Pflag, stdin_ok, vflag, Wflag;
 
 int	check(char *, char *, struct stat *);
 void	checkdot(char **);
@@ -96,7 +96,7 @@
 	(void)setlocale(LC_ALL, "");
 
 	Pflag = rflag = 0;
-	while ((ch = getopt(argc, argv, "dfiPRrW")) != -1)
+	while ((ch = getopt(argc, argv, "dfiPRrvW")) != -1)
 		switch (ch) {
 		case 'd':
 			dflag = 1;
@@ -116,6 +116,9 @@
 		case 'r':			/* Compatibility. */
 			rflag = 1;
 			break;
+		case 'v':
+			vflag = 1;
+			break;
 		case 'W':
 			Wflag = 1;
 			break;
@@ -149,7 +152,7 @@
 {
 	FTS *fts;
 	FTSENT *p;
-	int flags, needstat;
+	int flags, needstat, rval;
 
 	/*
 	 * Remove a file hierarchy.  If forcing removal (-f), or interactive
@@ -216,6 +219,7 @@
 				continue;
 		}
 
+		rval = 0;
 		/*
 		 * If we can't read or search the directory, may still be
 		 * able to remove it.  Don't print out the un{read,search}able
@@ -224,23 +228,32 @@
 		switch (p->fts_info) {
 		case FTS_DP:
 		case FTS_DNR:
-			if (!rmdir(p->fts_accpath) ||
-			    (fflag && errno == ENOENT))
+			rval = rmdir(p->fts_accpath);
+			if (rval == 0 || (fflag && errno == ENOENT)) {
+				if (rval == 0 && vflag)
+					(void)printf("%s\n", p->fts_path); 
 				continue;
+			}
 			break;
 
 		case FTS_W:
-			if (!undelete(p->fts_accpath) ||
-			    (fflag && errno == ENOENT))
+			rval = undelete(p->fts_accpath);
+			if (rval == 0 || (fflag && errno == ENOENT)) {
+				if (vflag)
+					(void)printf("%s\n", p->fts_path);
 				continue;
+			}
 			break;
 
 		default:
 			if (Pflag)
 				rm_overwrite(p->fts_accpath, NULL);
-			if (!unlink(p->fts_accpath) ||
-			    (fflag && NONEXISTENT(errno)))
+			rval = unlink(p->fts_accpath);
+			if (rval == 0 || (fflag && NONEXISTENT(errno))) {
+				if (rval == 0 && vflag)
+					(void)printf("%s\n", p->fts_path);
 				continue;
+			}
 		}
 		warn("%s", p->fts_path);
 		eval = 1;
@@ -298,6 +311,8 @@
 			warn("%s", f);
 			eval = 1;
 		}
+		if (vflag && rval == 0) 
+			(void)printf("%s\n", f);
 	}
 }
 
@@ -430,7 +445,7 @@
 usage(void)
 {
 
-	(void)fprintf(stderr, "usage: %s [-f|-i] [-dPRrW] file ...\n",
+	(void)fprintf(stderr, "usage: %s [-f|-i] [-dPRrvW] file ...\n",
 	    getprogname());
 	exit(1);
 	/* NOTREACHED */

--ZGiS0Q5IWpPtfppv--