Subject: rm.diff 3
To: None <tech-userlevel@netbsd.org>
From: Jason R. Fink <jrf@adresearch.com>
List: tech-userlevel
Date: 01/08/2003 12:38:45
--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello,

In this diff, the IMMUTABLES items were removed.
I would prefer someone else deal with that since
I cannot seem to make up my mind :-)

I kept the rval variable instead of just checking
against the call because it seems to make life
simpler (easy to read).

Note that we also check for removal of directories
that cannot be read or searched in rm_tree and
do a verbose print if successful (like whiteout
for example).

	j

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

--k+w/mQv8wyuph6w0
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/08 17:30:38
@@ -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/08 17:30:38
@@ -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,26 +228,35 @@
 		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;
 		}
-		warn("%s", p->fts_path);
-		eval = 1;
 	}
 	if (errno)
 		err(1, "fts_read");
@@ -298,6 +311,8 @@
 			warn("%s", f);
 			eval = 1;
 		}
+		if(vflag && rval == 0) 
+			(void)printf("%s\n", f);
 	}
 }
 

--k+w/mQv8wyuph6w0--