Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: rfc patch, abort rm instead of only removing the * from the cmdline



On Sat, Aug 16, 2008 at 10:58:19PM +0200, Mikael Magnusson wrote:
[...]
> It looks like it does abort the command if the * is the _only_ argument...
> I couldn't check easily as I already have the patch applied :).
> 
> % rm * --help
> zsh: sure you want to delete all the files in /home/mikachu/a [yn]? n
> Usage: rm [OPTION]... FILE...
> Remove (unlink) the FILE(s).
[...]

OK, I can reproduce it now. And I agree with you it wasn't quite
what I expected. But then, I think the fix should rather be
something like:

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.140
diff -p -u -r1.140 exec.c
--- Src/exec.c	13 Aug 2008 21:02:02 -0000	1.140
+++ Src/exec.c	17 Aug 2008 06:56:17 -0000
@@ -2547,19 +2547,24 @@ execcmd(Estate state, int input, int out
 
 	    next = nextnode(node);
 	    if (s[0] == Star && !s[1]) {
-		if (!checkrmall(pwd))
-		    uremnode(args, node);
+		if (!checkrmall(pwd)) {
+		    errflag = 1;
+		    break;
+		}
 	    } else if (l > 2 && s[l - 2] == '/' && s[l - 1] == Star) {
 		char t = s[l - 2];
+		int rmall;
 
 		s[l - 2] = 0;
-		if (!checkrmall(s))
-		    uremnode(args, node);
+		rmall = checkrmall(s);
 		s[l - 2] = t;
+
+		if (!rmall) {
+		    errflag = 1;
+		    break;
+		}
 	    }
 	}
-	if (!nextnode(firstnode(args)))
-	    errflag = 1;
     }
 
     if (errflag) {

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author