Subject: bin/5716: rm should have "-v" option
To: None <gnats-bugs@gnats.netbsd.org>
From: Matthias Scheler <tron@lyssa.owl.de>
List: netbsd-bugs
Date: 07/07/1998 00:08:27
>Number:         5716
>Category:       bin
>Synopsis:       rm should have "-v" option
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jul  6 15:20:01 1998
>Last-Modified:
>Originator:     Matthias Scheler
>Organization:
Matthias Scheler                                http://home.owl.de/~tron/
>Release:        980706
>Environment:
System: NetBSD lyssa.owl.de 1.3F NetBSD 1.3F (LYSSA) #0: Sun Jul 5 18:36:39 MEST 1998 tron@lyssa.owl.de:/src/src/sys/arch/i386/compile/LYSSA i386


>Description:
One of the nicest features of the GNU file utilities is their verbose mode.
When used with "-v" as argument they will print out what they are doing
so you can verify easily if everything worked as expected.

The included patch will add a "-v" option to our "rm" command.

>How-To-Repeat:
touch theo
rm -v theo

>Fix:
--- src/bin/rm/rm.1.orig	Mon Oct 20 14:26:19 1997
+++ src/bin/rm/rm.1	Tue Jul  7 00:01:44 1998
@@ -101,6 +101,8 @@
 .It Fl r
 Equivalent to
 .Fl R .
+.It Fl v
+Print the name of each file after removing it.
 .It Fl W
 Attempts to undelete the named files.
 Currently, this option can only be used to recover
--- src/bin/rm/rm.c.orig	Mon Jul  6 23:39:51 1998
+++ src/bin/rm/rm.c	Mon Jul  6 23:50:39 1998
@@ -62,7 +62,7 @@
 #include <pwd.h>
 #include <grp.h>
 
-int dflag, eval, fflag, iflag, Pflag, Wflag, stdin_ok;
+int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
 
 int	check __P((char *, char *, struct stat *));
 void	checkdot __P((char **));
@@ -97,7 +97,7 @@
 	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;
@@ -117,6 +117,9 @@
 		case 'r':			/* Compatibility. */
 			rflag = 1;
 			break;
+		case 'v':
+			vflag = 1;
+			break;
 		case 'W':
 			Wflag = 1;
 			break;
@@ -224,22 +227,37 @@
 		switch (p->fts_info) {
 		case FTS_DP:
 		case FTS_DNR:
-			if (!rmdir(p->fts_accpath) ||
-			    (fflag && errno == ENOENT))
+			if (!rmdir(p->fts_accpath)) {
+			    if (vflag)
+				(void)puts(p->fts_path);
+			    continue;
+			}
+			else
+			    if (fflag && errno == ENOENT)
 				continue;
 			break;
 
 		case FTS_W:
-			if (!undelete(p->fts_accpath) ||
-			    (fflag && errno == ENOENT))
+			if (!undelete(p->fts_accpath)) {
+			    if (vflag)
+				(void)puts(p->fts_path);
+			    continue;
+			}
+			else
+			    if (fflag && errno == ENOENT)
 				continue;
 			break;
 
 		default:
 			if (Pflag)
 				rm_overwrite(p->fts_accpath, NULL);
-			if (!unlink(p->fts_accpath) ||
-			    (fflag && NONEXISTENT(errno)))
+			if (!unlink(p->fts_accpath)) {
+			    if (vflag)
+				(void)puts(p->fts_path);
+			    continue;
+			}
+			else
+			    if (fflag && NONEXISTENT(errno))
 				continue;
 		}
 		warn("%s", p->fts_path);
@@ -295,6 +313,8 @@
 				rm_overwrite(f, &sb);
 			rval = unlink(f);
 		}
+		if (!rval && vflag)
+		    (void)puts(f);
 		if (rval && (!fflag || !NONEXISTENT(errno))) {
 			warn("%s", f);
 			eval = 1;
>Audit-Trail:
>Unformatted: