I think this is a bug, here is a fix obtained from NetBSD.

The reasoning (from NetBSD's rm.c,v 1.16):

Strip trailing slashes of operands in checkdot().

POSIX.2 requires that if "." or ".." are specified as the basename
portion of an operand, a diagnostic message be written to standard
error, etc.  We strip the slashes because POSIX.2 defines basename
as the final portion of a pathname after trailing slashes have been
removed.

This also makes rm "perform actions equivalent to" the POSIX.1
rmdir() and unlink() functions when removing directories and files,
even when they do not follow POSIX.1's pathname resolution semantics
(which require trailing slashes be ignored).

If nobody complains about this I will request for commit approval from [EMAIL 
PROTECTED]

Cheers,
-- 
Xin LI <[EMAIL PROTECTED]>      http://www.delphij.net/
FreeBSD - The Power to Serve!
Index: rm.c
===================================================================
RCS file: /home/ncvs/src/bin/rm/rm.c,v
retrieving revision 1.58
diff -u -p -r1.58 rm.c
--- rm.c        31 Oct 2006 02:22:36 -0000      1.58
+++ rm.c        25 Sep 2007 18:26:52 -0000
@@ -558,6 +558,14 @@ check2(char **argv)
        return (first == 'y' || first == 'Y');
 }
 
+/*
+ * POSIX.2 requires that if "." or ".." are specified as the basename
+ * portion of an operand, a diagnostic message be written to standard
+ * error and nothing more be done with such operands.
+ *
+ * Since POSIX.2 defines basename as the final portion of a path after
+ * trailing slashes have been removed, we'll remove them here.
+ */
 #define ISDOT(a)       ((a)[0] == '.' && (!(a)[1] || ((a)[1] == '.' && 
!(a)[2])))
 void
 checkdot(char **argv)
@@ -567,10 +575,17 @@ checkdot(char **argv)
 
        complained = 0;
        for (t = argv; *t;) {
+               /* strip trailing slashes */
+               p = strrchr(*t, '\0');
+               while (--p > *t && *p == '/')
+                       *p = '\0';
+
+               /* extract basename */
                if ((p = strrchr(*t, '/')) != NULL)
                        ++p;
                else
                        p = *t;
+
                if (ISDOT(p)) {
                        if (!complained++)
                                warnx("\".\" and \"..\" may not be removed");

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to