bug-coreutils
[Top][All Lists]
Advanced

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

Re: "chmod -w file" now complains if file is still writable afterwards


From: Eric Blake
Subject: Re: "chmod -w file" now complains if file is still writable afterwards
Date: Wed, 04 May 2005 23:28:31 +0000

> This is a common trap for novices to fall into, and I think it'd be
> better if chmod diagnosed the mistake, in addition to performing the
> requested action.  I just checked POSIX, and it allows "chmod" to
> diagnose errors like "chmod -w file" so I installed the following
> patch.

It took me a while to follow your logic of how POSIX allows this, so I'm
stating why I am in agreement.  The only option chmod is required to
support is -R, so we can define our own semantics for extension options
such as -w, -r, etc., where our extension options happen to look like valid
mode strings.  There is definitely a parsing difference between
`chmod -- any-mode file' or `chmod non-dash-mode file' with 0 options
and 2 arguments, and `chmod -dash-mode file' with 1 option
and 1 argument, and POSIX only dictates the behavior of the first.

Other questions, though - with our extension options, should we interpret
`chmod -w a+x foo' the same as `chmod -- -w ./a+x ./foo' or like
`chmod -- -w,a+x ./foo'?  Put in other words, if the first of multiple
non-option arguments matches a mode, should it be treated as a mode
or a file when extension options are present.  Also, POSIX allows modes
that look like long options - can the code be made to treat `chmod --w foo'
the same as it would `chmod -w foo' by seeing if unrecognized long options
match a valid mode string?

> 
> Another option would be for "chmod -w file" to silently adjust itself
> to behave like "chmod a-w file"; POSIX allows that too.  If you think
> that's better I could install a patch along those lines instead.
> 

I tend to favor your existing patch as the correct approach.  I would find
it confusing if the extension syntax `chmod -w file' behaved differently
than the compliant syntax `chmod -- -w file' on which permissions it
affected, unless we documented the -w extension better.

Speaking of which, the `chmod --help' wording could be improved (perhaps
with examples); it does not mention -w, -r, etc. as being extension options,
and wrongly states that "one or more of the letters ugoa" is required as who,
and "one or more of the letters rwxXstugo" is required as perm/permcopy.

--
Eric Blake






reply via email to

[Prev in Thread] Current Thread [Next in Thread]