1. Antoine Pitrou
  2. pathlib
Issue #9 resolved

Path.resolve() fails on complex symlinks

Serhiy Storchaka
created an issue

Path.resolve() fails on such example:

mkdir testdir ln -s . testdir/0 ln -s 0/0 testdir/1 ln -s 1/1 testdir/2

and then resolve "testdir/2".

The script which tests pathlib for this and more complex examples is attached.

http://bugs.python.org/issue6975 has a patch for posixpath.realpath() which passes the test.

Comments (7)

  1. Antoine Pitrou repo owner

    Which behaviour is expected exactly? I get the same results as with os.path.realpath():

    $ python3.4 -c "import os; print(os.path.realpath('testdir/2'))"
    /home/antoine/pathlib/testdir
    $ python3.4 -c "import pathlib; print(pathlib.Path('testdir/2').resolve())"
    /home/antoine/pathlib/testdir
    $ hg sum
    parent: 140:bf75f7cec23f tip
     Make touch() POSIX-compliant
    branch: pep428
    commit: 4 unknown (clean)
    update: (current)
    
  2. Antoine Pitrou repo owner

    Also the shell gives me the same results:

    $ stat testdir/
      Fichier : «testdir/»
       Taille : 4096        Blocs : 8          ES blocs : 4096   répertoire
    Device : 815h/2069d Inode : 7471393     Liens : 2
    Accès : (0755/drwxr-xr-x)  UID : ( 1000/ antoine)   GID : ( 1000/ antoine)
    Accès : 2013-12-02 23:36:10.298937391 +0100
    Modi. : 2013-12-02 23:36:10.238937393 +0100
    Chgt  : 2013-12-02 23:36:10.238937393 +0100
    Créé  : -
    $ stat testdir/2/
      Fichier : «testdir/2/»
       Taille : 4096        Blocs : 8          ES blocs : 4096   répertoire
    Device : 815h/2069d Inode : 7471393     Liens : 2
    Accès : (0755/drwxr-xr-x)  UID : ( 1000/ antoine)   GID : ( 1000/ antoine)
    Accès : 2013-12-02 23:36:10.298937391 +0100
    Modi. : 2013-12-02 23:36:10.238937393 +0100
    Chgt  : 2013-12-02 23:36:10.238937393 +0100
    Créé  : -
    
  3. Antoine Pitrou repo owner

    However pathlib still fails last test in the script.

    It's a ENAMETOOLONG error when calling readlink(), because there are many "." components. This is really an edge case caused by the specific test setup, I don't think you'd have that many "." components in real-world use.

  4. Log in to comment