public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Christopher Faylor <cgf-use-the-mailinglist-please@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: stat() and tilde prefix (was bad bash tab completion)
Date: Mon, 14 Jan 2013 15:27:00 -0000	[thread overview]
Message-ID: <20130114152714.GC27617@ednor.casa.cgf.cx> (raw)
In-Reply-To: <20130114100002.GA22039@calimero.vinschen.de>

On Mon, Jan 14, 2013 at 11:00:02AM +0100, 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.
>
>POSIX demands to evaluate a path from left to right (thus tripping over
>the non-existant "~" or "foo" directory).  Windows OTOH skips testing
>all parent directories of a path, and while this can be changed(*), it's
>the default setting since the earliest Windows NT versions.
>
>So, since Cygwin can't rely on the OS to this job when it has to convert
>a POSIX path to a Windows path internally, Cygwin would have to check
>the existence of every single path component from left to right to
>emulate the POSIX requirements.  But that would be a big performance
>hit, so Cygwin's path handling code tries to be clever to avoid having
>to call too many OS functions:
>
>The first step of converting a POSIX path to a Windows path is to
>normalize the path.  "." and ".." components are simply dropped:
>
>  "a/b/./c"  -> "a\b\c"
>  "a/b/../c" -> "a\c"
>
>Then the path prefix is replaced by the matching mount point.
>
>Eventually it evaluates the path from right to left.  Consider a valid,
>normalized path with 10 components.  Under POSIX rules this requires 10
>checks for existence.  No problem for the Linux kernel since it has
>everything under control anyway and the test is blazingly fast.
>
>But Cygwin is not the OS so it has to call the necessary OS functions 10
>times.  By checking from right to left, Cygwin has to call the OS
>functions only once, if the file exists, two times if the file does not
>exist, but its parent dir exists, and so on.  On top of that, the entire
>chore has to restart when tripping over a symbolic link.
>
>Since the predominant number of file operations are performed on
>existing paths, or at least paths for which the parent dir exists,
>Cygwin reduces the number of OS operations to convert a POSIX to a
>Windows path.  The price we're paying is this very deviation from the
>POSIX standard.

Also:

  c:\>dir foo\bar\..\..

   Volume in drive S is share          Serial number is e620:3c3d
   Directory of  S:\*

   1/11/2013   9:58         <DIR>    .
  12/26/2012  21:34         <DIR>    ..
   1/12/2013  16:27         <DIR>    bin
   1/14/2013  10:20         <DIR>    cgf
   ...

I don't have a foo directory but cmd was happy to just ignore that
fact and show my the root directory.  This is YA place where Windows
and Linux differ drastically.

cgf

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

  parent reply	other threads:[~2013-01-14 15:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-10 14:25 bad bash tab completion Shaddy Baddah
2012-08-10 16:54 ` Eric Blake
2013-01-14  5:21 ` stat() and tilde prefix (was bad bash tab completion) Shaddy Baddah
2013-01-14  6:17   ` Christopher Faylor
2013-01-14 12:23     ` Corinna Vinschen
2013-01-14 14:37       ` Shaddy Baddah
2013-01-14 16:13         ` Corinna Vinschen
2013-01-14 20:29           ` Stephan Mueller
2013-01-14 21:37             ` Ryan Johnson
2013-01-15  8:44               ` Corinna Vinschen
2013-01-15 12:33           ` Shaddy Baddah
2013-02-07  7:00             ` Shaddy Baddah
2013-02-07 15:32               ` Eric Blake
2013-02-07 16:10                 ` Thomas Wolff
2013-02-07 16:24                   ` Corinna Vinschen
2013-02-07 16:26                     ` Christopher Faylor
2013-01-14 15:27       ` Christopher Faylor [this message]
2013-01-14 16:05         ` Corinna Vinschen
2013-01-14 17:00           ` Christopher Faylor
2013-01-14 22:15       ` Thomas Wolff
2013-01-15  8:56         ` Corinna Vinschen
2013-01-15 19:50         ` Andrey Repin
2013-01-15 20:03           ` Larry Hall (Cygwin)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130114152714.GC27617@ednor.casa.cgf.cx \
    --to=cgf-use-the-mailinglist-please@cygwin.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).