This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ash is wrong about [ -w Temp ], so rebaseall fails

On Wed, 30 Nov 2011, Eric Blake wrote:
On 11/30/2011 03:17 PM, Tim McDaniel wrote:
$ /bin/ash -c ' [ -w /Users/tmcdaniel/AppData/Local/Temp ] && echo yes
|| echo no'

So bash and ash disagree on whether this Temp directory is writable.

Known limitation in dash - it is going off of just st_mode bits instead of using faccessat() and honoring ACLs.

I think that's the case.

I've been meaning to do a new build of dash (aka ash), and to force
the use of faccessat as part of that build; I just haven't had the
time to get to it yet.

In the meantime, though, rebaseall as distributed did not work for me.

There's a general principle that, if you want to find out whether you
can do an operation, you should not check permissions bits, but
instead just try to do what you want to do and check for errors -- for
this very reason, that your test may not be accurate, and also because
if it's so critical an operation, you should be checking for errors
anyway when you do it.

So I suggest that

# Validate temp directory
if [ ! -d "$TmpDir" ]
    echo "$ProgramName: '$TmpDir' is not a directory"
    exit 2
if [ ! -w "$TmpDir" ]
    echo "$ProgramName: '$TmpDir' is not writable"
    exit 2

be removed, and that the check instead be done just before writing it
for real:

# Create rebase list
# This creates an empty file if you have permission to do so,
# and outputs an error message if not.
if ! > "$TmpFile"; then
    echo "$ProgramName: cannot write to temporary file in '$TmpDir'" 1>&2
    exit 2
case $Platform in

I've tested this proposal briefly and it appears to work, though I
can't really try it for real, because I'd have to close this window.

Even better might be to check every command that tries to > or >> on

Tim McDaniel

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]