bug-coreutils
[Top][All Lists]
Advanced

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

Re: possible new feature for chmod


From: Steve Summit
Subject: Re: possible new feature for chmod
Date: Thu, 07 Aug 2003 10:10:08 -0400

Thanks for your interest in the idea.

My own feeling is that explicitly disambiguating an ls-style mode
string (e.g. by prefixing it with '%', as Paul has suggested) is
a nice solution to something that shouldn't be a problem.  If it
were 10 years ago, without Posix to worry about, we could just
throw this out there, and be done with it.  (But I hasten to add
that, yes, I realize it's not 10 years ago, and we should worry
about Posix.)

I was taken quite by surprise to discover that, say, "-rw-rw-r-"
is a valid, Posix-style mode string at all.  Do we really imagine
that someone is ever going to deliberately use such a string, and
expect it to be interpreted as Posix says it would?  My concern
was the opposite, that someone would type such a string,
intending it to be interpreted as an ls-style mode string, and
get unexpected results when it was processed as a Posix-style
mode string, instead.

I don't have a copy of Posix.1 handy, but I gather from
inspection of chmod's source code that the allowable forms are
supposed to be one or more comma-separated "terms", where each
term is an optional character from the set [ugoa] followed by
one or more additions or subtractions, where an addition or
subtraction is the character '+' or '-' or '=' followed by zero
or more characters from the set [rwxXstugo].  Now, I assume Posix
doesn't say so, but I think we can agree that a single "term"
that contains two separate '-'s (or two '+'s or two '='s, for
that matter) is borderline, and a term that contains two '-'s
followed by the same characters, or a '-' not followed by any
character at all, is bogus, and that any of these is deserving of
at least a warning.

Let's be sure we understand the cases we're talking about.
A string like

        -rw-rw-r-

is not a valid ls-style mode string (at least, not by the
definition of the code I added), and so falls through to be
parsed as a Posix-style mode string, in a Posix-conformant way,
although it now also draws a warning in case it was intended as
an ls-style string.  Strings like

        rw-rw-r--
and
        drwxr-xr-x

are valid ls-style mode strings, are not valid Posix-style mode
strings, and so can be parsed as ls-style with no ambiguity or
Posix nonconformance.  The only truly ambiguous case is
exemplified by

        -rw-rw-r--

Paul's right: this one would have to be disallowed for strict
Posix compliance, i.e. in the face of POSIXLY_CORRECT, and I
hadn't thought of this.  (But again, I can't imagine that anyone
would ever actually use such a string and expect it to be
interpreted as a-rw-rw-r--, i.e. as a redundant longwinded form
of a-rw.)

The leading %, clever as it is in absolutely ruling out the
faintest possible of ambiguity, bothers me, because it seems
arbitrary and unnecessary (and therefore ugly).  If the founding
fathers had had this idea back in Unix's youth, they wouldn't have
felt the need for explicit disambiguation; they would have felt
(I feel) that the normal usages of the two styles of strings were
syntactically far enough apart that implicit disambiguation would
be sufficient.  And it seems to me we could still get away with
this today, although I freely admit I could be wrong.




reply via email to

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