delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2013/01/14/15:17:58

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Mon, 14 Jan 2013 17:13:07 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: stat() and tilde prefix (was bad bash tab completion)
Message-ID: <20130114161307.GB8617@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <5024B4D4 DOT 6080409 AT shaddybaddah DOT name> <50F395D5 DOT 4050201 AT shaddybaddah DOT name> <20130114061747 DOT GB16739 AT ednor DOT casa DOT cgf DOT cx> <20130114100002 DOT GA22039 AT calimero DOT vinschen DOT de> <50F417F9 DOT 8040108 AT shaddybaddah DOT name>
MIME-Version: 1.0
In-Reply-To: <50F417F9.8040108@shaddybaddah.name>
User-Agent: Mutt/1.5.21 (2010-09-15)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 Jan 15 01:36, Shaddy Baddah wrote:
> Hi,
> 
> On 14/01/13 21:00, Corinna Vinschen wrote:
> >On Jan 14 01:17, Christopher Faylor wrote:
> >>On Mon, Jan 14, 2013 at 04:21:25PM +1100, Shaddy Baddah wrote:
> >>>In investigating this, I believe the issue I am having is due to how
> >>>stat() handles tilde prefixed paths. On linux we see:
> >>>
> >>>linux$ $ python -c 'import os; print os.stat("~/..")'
> >>>Traceback (most recent call last):
> >>>   File "<string>", line 1, in<module>
> >>>OSError: [Errno 2] No such file or directory: '~/..'
> >>>
> >>>and on cygwin we see:
> >>>
> >>>cygwin$ python -c 'import os; print os.stat("~/..")'
> >>>posix.stat_result(st_mode=16832, st_ino=562949953496729L,
> >>>st_dev=4174909669L, st_nlink=1, st_uid=42037, st_gid=10513, st_size=0L,
> >>>st_atime=1357616166, st_mtime=1357616166, st_ctime=1357616166)
> >>
> >>It is a bug.  It's not just "~".  Any nonexistent directory will
> >>work, like "foo/..".
> >
> >And it's a bug which isn't easily fixed.  Since about the dawn of time,
> >Cygwin's core path handling evaluates the path in a non-POSIX manner,
> >mainly for performance reasons.
> 
> Thank you both for your explanations. If my understanding is correct,
> stat() will be returning for the current working directory.

In the above case, yes.

> It seems to me then that a patch to bash may be in order? I can see how
> the bash check is the right thing to do. It doesn't want the special
> tilde expansion to mask and disallow referencing of real tilde prefixed
> paths. So the stat() check is the quick win to determine that.
> 
> From what I make of it, there needs to be a patch that, although can
> work generically, adds checks only required for Cygwin. And therefore
> is specific to the Cygwin package.
> 
> The check would be an extension of the file_exists() function, perhaps
> called tilde_file_exists(), which determines if the tilde prefix forms
> a directory component of the path (strchr('/')?). If it does not, the
> file_exists() check is sufficient. If it does, then the check of if
> that directory exists is logically and'ed to the result of
> file_exists().
> 
> Does that sound about right?

A check like this might be a good idea.  Ultimately I would be glad to
be able to come up with more correct code in Cygwin while not getting
slower, of course.  But that's wishful thinking for now.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019