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: site.py can break the location of the python library
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, mwm
Priority: normal Keywords:

Created on 2006-06-29 22:32 by mwm, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg60933 - (view) Author: Mike Meyer (mwm) Date: 2006-06-29 22:32
Given a sufficiently bizarre(*) set of symlinks on a posix system,
site.py will change the directories in sys.path in such a way that
they will no longer refer to valid directories. In the
following. os.path refers to the posixpath file.

The root of the problem is that site.makepath invokes os.path.abspath
on it's paths, which calls os.path.normpath. os.path.normpath assumes
that changing "foo/bar/../baz" to "foo/baz". This isn't true if bar is
a symlink to somewhere where ../baz exists, but foo/baz doesn't.

The simple fix is to make site.py call os.path.realpath on the path
before calling os.path.abspath. This may not be the best fix. Possibly
os.path.abspath should call realpath instead of normpath. Maybe
normpath should check for symlinks and deal with them, effectively
making it an alias for realpath. However, those both change the
behavior of library functions, which may not be desirable.

Here's a patch for site.py that fixes the problem:

--- site.py	Thu Jun 29 18:14:08 2006
+++ site-fixed.py	Thu Jun 29 18:13:57 2006
@@ -63,7 +63,7 @@
 
 
 def makepath(*paths):
-    dir = os.path.abspath(os.path.join(*paths))
+    dir = os.path.abspath(os.path.realpath(os.path.join(*paths)))
     return dir, os.path.normcase(dir)
 
 def abs__file__():


*) Python is invoked as /cm/tools/bin/python. That's a symlink to
../../paks/Python-2.4.3/bin/python, and the library is in
../../paks/Python-2.4.3/lib. /cm/tools/bin is a symlink to
/cm/tools/apps/bin. /cm/tools is a symlink to
/opt/local/cmtools. Changing that relative symlink to an absolute one
fixes the problem, but violates installation guidelines. Trying to
recreate this without all three symlnks in place inevitably fails to
reproduce the problem. And no, I didn't create this. I just diagnosed
it.

msg85143 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-04-02 02:46
The semantics of the functions in os cannot change. And I prefer keeping
it as-is since I wouldn't want to change the symlinks on a relative path.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43584
2009-04-02 02:46:36brett.cannonsetstatus: open -> closed
assignee: brett.cannon ->
resolution: wont fix
messages: + msg85143
2009-02-11 03:06:51ajaksu2setassignee: brett.cannon
nosy: + brett.cannon
2006-06-29 22:32:41mwmcreate