[Python-Dev] os.normpath may change the meaning of the path if itcontains symbolic links?

Fredrik Lundh fredrik at pythonware.com
Fri Dec 2 23:34:34 CET 2005


Nir Soffer wrote:

> However, I found this alarming note in the docs:
>
> normpath(path)
> ...
> "It should be understood that this may change the meaning of the path
> if it contains symbolic links!"
>
> The function docstring does not contain this note:
>
> """Normalize path, eliminating double slashes, etc."""
>
> And finally, there is no test for this symbolic link problem.
>
> Anyone has a clue about this?

if BAR is a symbolic link, FOO/BAR/../DIR isn't necessarily the same
thing as FOO/DIR.

a simple example:

    $ ln -s /etc etc
    $ ls -ld etc
    lrwxrwxrwx    1 fredrik  fredrik         4 Dec  2 23:22 etc -> /etc
    $ etc/../usr/local/bin/python2.4
    Python 2.4.1 (#1, Sep 12 2005, 19:35:02)
    ...
    >>> import os
    >>> os.path.normpath("etc/../usr/local/bin/python2.4")
    'usr/local/bin/python2.4'
    >>> <control-D>
    $ usr/local/bin/python2.4
    -bash: usr/local/bin/python2.4: No such file or directory

</F> 





More information about the Python-Dev mailing list