X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Date: Wed, 30 Nov 2011 17:12:41 -0600 (CST) From: Tim McDaniel To: cygwin AT cygwin DOT com Subject: Re: ash is wrong about [ -w Temp ], so rebaseall fails In-Reply-To: <4ED6B224.6080702@redhat.com> Message-ID: References: <4ED6B224 DOT 6080702 AT redhat DOT com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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' >> 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" ] then echo "$ProgramName: '$TmpDir' is not a directory" exit 2 fi if [ ! -w "$TmpDir" ] then echo "$ProgramName: '$TmpDir' is not writable" exit 2 fi 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 fi 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 TmpFile. -- Tim McDaniel -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple