I'll pay $40 in e-gold if you'll fix this bug.

Michael P. Reilly arcege at shore.net
Tue Jun 8 10:48:57 EDT 1999


Jan Walter <jan at q-bus.de> wrote:
: Hi,

: Maybe you get confused a bit by the bash!!!

: Try following:
: bash$ tcsh
: tcsh: cd /tmp/
: tcsh: mkdir dirOne
: tcsh: mkdir dirTwo
: tcsh: mkdir dirTwo/dirThree
: tcsh: ln -s dirTwo/dirThree/ .
: tcsh: cd dirThree/
: tcsh: pwd
: /tmp/dirTwo/dirThree

: Do the same with the bash (removing the directories of course):
: bash$ cd /tmp/
: bash$ mkdir dirOne
: bash$ mkdir dirTwo
: bash$ mkdir dirTwo/dirThree
: bash$ ln -s dirTwo/dirThree/ .
: bash$ cd dirThree/
: bash$ pwd
: /tmp/dirThree

: The tcsh gives the right answer. You are in the /tmp/dirTwo/dirThree directory. If you try
: to move a file with "mv file.txt ../dirOne/file.txt" you can at t do that because there is no
: directory dirOne !!!

: Python works like tcsh. If you try the following you get the right answer:
: bash$ cd /tmp/dirThree/
: bash$ python
: Python 1.5.1 (#1, May  6 1998, 01:48:27)  [GCC 2.7.2.3] on linux-i386
: Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
:>>> import os
:>>> os.getcwd()
: '/tmp/dirTwo/dirThree'

: My suggestion:

: You can test if there are symbolic links in your path (e.g. os.path.islink("/tmp/dirThree")
: within Python) or you can prove that /tmp/dirThree is in reality /tmp/dirTwo/dirThree and
: life with that fact ...

: Cheers,

: Jan

It is not a matter of "correctness", but of perceived current
pathname.  In that same tcsh, if you echo $cwd, you will get the same
value that bash returns,  there are some systems where using this
"faked" value is required (Automounter V1 systems for example).  Both
csh and tcsh have common, documentated add-ons (alias pwd 'echo $cwd')
to give the same functionality as bash.

But, the getcwd(3) C function performs a call to traverse up the tree
to retrieve the pathname.  This is because a process only holds the
inode of the current directory, not the path that got it there.

Using relative pathnames with symbolic links is problematic at times,
but they aren't "incorrect."  Symbolic links have to be organized
properly; if they are not, you have odd side-effects.  These are the
Facts of Life (I always like "Jo" myself).

  -Arcege





More information about the Python-list mailing list