[ python-Bugs-1514734 ] site.py can break the location of the python library

SourceForge.net noreply at sourceforge.net
Fri Jun 30 00:32:42 CEST 2006


Bugs item #1514734, was opened at 2006-06-29 17:32
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1514734&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Mike Meyer (mwm)
Assigned to: Nobody/Anonymous (nobody)
Summary: site.py can break the location of the python library

Initial Comment:
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.



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1514734&group_id=5470


More information about the Python-bugs-list mailing list