This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: double symlinking corrupts sys.path[0]
Type: Stage:
Components: Interpreter Core Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: dzsekijo, staschuk, tzot
Priority: normal Keywords:

Created on 2003-08-24 19:52 by dzsekijo, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Messages (5)
msg17938 - (view) Author: Csaba Henk (dzsekijo) Date: 2003-08-24 19:52
The bug can be demonstrated as follows

(In some Bourne-tpye Unix shell) type 

$ mkdir d1 d2 && 
echo 'import sys
print sys.path[0]' > d1/script.py &&
ln -s ../d1/script.py d2 && 
ln -s d2/script.py .

Now see what the  three invocations of  script.py give us:

$ python d1/script.py 
d1
$ python d2/script.py 
d2/../d1
$ python script.py 
d2

--  if script.py imported modules residing in d1, at
the third invocation the modules would not be found.
msg17939 - (view) Author: Χρήστος Γεωργίου (Christos Georgiou) (tzot) * Date: 2003-08-27 11:45
Logged In: YES 
user_id=539787

Which version of Python?  With a recent 2.4 (built on Aug 21, 
sources of Aug 20), on a 2.4.19 SMP kernel:

$ mkdir d1 d2
$ echo 'import sys
> print sys.path[0]' >d1/script.py
$ ln -s ../d1/script.py d2
$ ln -s d2/script.py .
$ python d1/script.py
/tmp/tzot/d1
$ python d2/script.py
/tmp/tzot/d1
$ python script.py
/tmp/tzot/d1

Please specify OS too.
msg17940 - (view) Author: Χρήστος Γεωργίου (Christos Georgiou) (tzot) * Date: 2003-08-27 11:46
Logged In: YES 
user_id=539787

My mistake, I missed the Pyhton 2.2.2 part, sorry.
msg17941 - (view) Author: Csaba Henk (dzsekijo) Date: 2003-08-27 15:29
Logged In: YES 
user_id=754125

I hope the startup message is exact enough:

Python 2.2.2 (#1, May 19 2003, 03:15:27) 
[GCC 3.1] on linux2
msg17942 - (view) Author: Steven Taschuk (staschuk) Date: 2003-08-28 05:39
Logged In: YES 
user_id=666873

I confirm this behaviour on Linux 2.4.17 (glibc 2.2.4) with Python 
2.2.2 and 2.2.3; but not with Python 2.3.

The relevant change seems to be revision 2.114 of 
Python/sysmodule.c, which implemented SF patch #664376 (q.v.). 
 The change appeared in 2.3a2.

Should this be backported to the 2.2 line?
History
Date User Action Args
2022-04-10 16:10:49adminsetgithub: 39120
2003-08-24 19:52:51dzsekijocreate