I have rm aliased to '/bin/rm -P', mostly for fun, but I like the idea. There is an oddity however when you use the -P flag, and the file is not writable. The check() function in rm.c specifically ignores this condition, and lets the thing fail later in the program. I think this is bad on an objective level, but it definitely leads to annoying problems for the user when you hit this condition. I therefore propose the attached patch.

Doug

--

    This .signature sanitized for your protection

Index: rm.c
===================================================================
RCS file: /usr/local/ncvs/src/bin/rm/rm.c,v
retrieving revision 1.52
diff -u -r1.52 rm.c
--- rm.c        13 Nov 2004 04:07:01 -0000      1.52
+++ rm.c        23 Sep 2005 08:29:38 -0000
@@ -452,11 +452,8 @@
                 * talking to a terminal, ask.  Symbolic links are excluded
                 * because their permissions are meaningless.  Check stdin_ok
                 * first because we may not have stat'ed the file.
-                * Also skip this check if the -P option was specified because
-                * we will not be able to overwrite file contents and will
-                * barf later.
                 */
-               if (!stdin_ok || S_ISLNK(sp->st_mode) || Pflag ||
+               if (!stdin_ok || S_ISLNK(sp->st_mode) ||
                    (!access(name, W_OK) &&
                    !(sp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
                    (!(sp->st_flags & (UF_APPEND|UF_IMMUTABLE)) || !uid)))
@@ -464,6 +461,9 @@
                strmode(sp->st_mode, modep);
                if ((flagsp = fflagstostr(sp->st_flags)) == NULL)
                        err(1, "fflagstostr");
+               if (Pflag)
+                       errx(1,
+                           "-P was specified, but %s is not writable", path);
                (void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ",
                    modep + 1, modep[9] == ' ' ? "" : " ",
                    user_from_uid(sp->st_uid, 0),

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to