◐ Shell
clean mode source ↗

Issue 6612: 'import site' fails when called from an unlinked directory

I don't imagine this comes up very often, but:

$ mkdir /tmp/a; cd /tmp/a; rmdir /tmp/a; python -c 'import site';
rmdir: removing directory, /tmp/a
'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/wking/lib/python/site.py", line 73, in <module>
    __boot()
  File "/home/wking/lib/python/site.py", line 33, in __boot
    imp.load_module('site',stream,path,descr)
  File "/usr/lib/python2.5/site.py", line 408, in <module>
    main()
  File "/usr/lib/python2.5/site.py", line 392, in main
    paths_in_sys = removeduppaths()
  File "/usr/lib/python2.5/site.py", line 96, in removeduppaths
    dir, dircase = makepath(dir)
  File "/usr/lib/python2.5/site.py", line 72, in makepath
    dir = os.path.abspath(os.path.join(*paths))
  File "/usr/lib/python2.5/posixpath.py", line 403, in abspath
    path = join(os.getcwd(), path)
OSError: [Errno 2] No such file or directory
There was a bug in copy_absolute(): if _Py_wgetcwd() failed, the result was undefined (depending of the content of "path" buffer). Especially, absolutize() calls copy_absolute() with a buffer allocated on the stack: the content of this buffer depends on the undefined content of the stack.

Fixed in Python 3.2 (r85309+r85311), 2.7 (r85312) and 3.1 (r85313).

copy_absolute() is used (by calculate_path()) to fill sys.path.