DragonFly BSD
DragonFly submit List (threaded) for 2004-09
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: bin/rmdir -p option bug [patch]


From: Joerg Sonnenberger <joerg@xxxxxxxxxxxxxxxxx>
Date: Wed, 8 Sep 2004 17:00:46 +0200

On Thu, Jul 22, 2004 at 08:39:44PM +0200, Douwe Kiela wrote:
> Hey peeps,
> 
> According to SUSv3, the -p option should behave exactly the same as rmdir
> without any option, only that it recursively removes all directories
> mentioned
> as arguments in the command line. In the current rmdir, you can't remove
> multiple directories and meanwhile recursively remove all it's
> subdirectories.

It still doesn't work as expected. What do you think of the attached patch?

Joerg
Index: Makefile
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/bin/rmdir/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- Makefile	17 Jun 2003 04:22:50 -0000	1.2
+++ Makefile	8 Sep 2004 14:57:32 -0000
@@ -4,6 +4,6 @@
 
 PROG=	rmdir
 
-WARNS?=	2
+WARNS?=	6
 
 .include <bsd.prog.mk>
Index: rmdir.c
===================================================================
RCS file: /home/joerg/wd/repository/dragonflybsd/src/bin/rmdir/rmdir.c,v
retrieving revision 1.5
diff -u -r1.5 rmdir.c
--- rmdir.c	24 Jul 2004 10:47:10 -0000	1.5
+++ rmdir.c	8 Sep 2004 14:58:13 -0000
@@ -69,11 +69,12 @@
 		usage();
 
 	for (errors = 0; *argv; argv++) {
-		if (rmdir(*argv) < 0) {
+		if (pflag) {
+			errors |= rm_path(*argv);
+		} else if (rmdir(*argv) < 0) {
 			warn("%s", *argv);
 			errors = 1;
-		} else if (pflag)
-			errors |= rm_path(*argv);
+		}
 	}
 
 	exit(errors);
@@ -85,10 +86,7 @@
 	char *p;
 
 	p = path + strlen(path);
-	while (--p > path && *p == '/')
-		;
-	*++p = '\0';
-	while ((p = strrchr(path, '/')) != NULL) {
+	do {
 		/* Delete trailing slashes. */
 		while (--p > path && *p == '/')
 			;
@@ -99,6 +97,7 @@
 			return (1);
 		}
 	}
+	while ((p = strrchr(path, '/')) != NULL);
 
 	return (0);
 }


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]