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]

stat() and tilde prefix (was bad bash tab completion)


Hi,

On 10 Aug 2012 17:14, Shaddy Baddah wrote:
I've been having this problem with bash for about half a year now. I
can't remember the specific upgrade that caused it, but that's around
the time frame.

So the issue is with tab completion, and looks something like this:

snapshot 1:

$ cd ~/../

snapshot 2 (after tab-tab):

$ cd \~/../

snapshot 3 (after further tab-tab):

$ cd \~/../
.ssh/ tmp/ workarea/

My main problem is with snapshot 2. By my understanding, the path that
bash has modified to is no longer a valid path. snapshot 3, and further
actions from there back it up, because bash is no longer looking in the
right place.

I have tried this with bash-completions disabled, and the same thing
happens.
</snip>
(see http://cygwin.com/ml/cygwin/2012-08/msg00226.html)

Sorry to drag this old email up, but it gives context to what I am about
to write.

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)


This make sense as the reason in the context of the bash code which
handles the tab-completion. It is escaping the path as it thinks it
references an actual valid posix path (according to my understanding
that the tilde has no special meaning to the posix api):

http://git.savannah.gnu.org/cgit/bash.git/tree/bashline.c?id=509a4430ae72aec10896713435e84f5b27675763#n3480

/* XXX -- check for standalone tildes here and backslash-quote them */
if (s == text && *s == '~' && file_exists (text))
*r++ = '\\';


where file_exists() just wraps stat():

http://git.savannah.gnu.org/cgit/bash.git/tree/general.c?id=509a4430ae72aec10896713435e84f5b27675763#n537

int
file_exists (fn)
     char *fn;
{
  struct stat sb;

  return (stat (fn, &sb) == 0);
}

Going back through various Cygwin dll versions, I see that stat() has
behaved in this way since as early as 1.7.6 if not earlier. I am unsure
if previous versions of bash had special handling for this stat()
behaviour, so it may be that bash has behaved this way for quite a while
longer that I had detected.

Can this be fixed? It seems like a change that may be tricky for other
applications?

--
Regards,
Shaddy

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


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