You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""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."""
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/pathlib.py", line 1017, in resolve
s =self._flavour.resolve(self)
File "/home/serhiy/py/cpython/Lib/pathlib.py", line 273, in resolveraiseRuntimeError("Symlink loop from %r"% cur)
RuntimeError: Symlink loop from '/home/serhiy/py/cpython/testdir/0'
Here is a patch which implements an algorithm similar to the algorithm used in posixpath.realpath().
vajrasky commented on Dec 5, 2013
vajraskymannequin
Mannequin
More actions
Whoa, Serhiy, your patch won't fly on Windows Vista.
For starter, the patch does not use target_is_directory=True option in os.symlink. It needs that option when creating symlink to the directory on Windows Vista.
The maximum depth that pathlib can do on Windows Vista is 4 (Remember, this line: "for depth in 0, 1, 2, 3, 10, 100"?).
More than that:
OSError: [WinError 1921] The name of the file cannot be resolved by the system:
'C:\\Users\\vajrasky\\Code\\cpython\\@test_4220_tmp\\testdir\\link5'
Not sure whether the bug is in pathlib.py or _getfinalpathname (from nt module).
Thank you Vajrasky. Here is a patch with fixed tests.
vajrasky commented on Dec 5, 2013
vajraskymannequin
Mannequin
More actions
It works. Just a coding nitpick, instead of hardcoding os.symlink(src, dst, target_is_directory=True) in the test, you can use helper function in the test itself, self.dirlink.
How the test can be simpler? It is already simple.
You ca use pathlib_resolve_test.py but replace os.symlink('.', 'testdir/0') by os.symlink(os.path.abspath('testdir'), 'testdir/0'). Or use following shell commands:
mkdir testdir
for i in $(seq 100); do ln -s $((i-1))/$((i-1)) testdir/$i; done
ln -s "$(pwd)/testdir" testdir/0
How the test can be simpler? It is already simple.
I mean, don't use loops but a simple test setup as in test_resolve_dot.
I am not interested in the pathologic "100 symlinks" case, just the case where the symlink is absolute.
vajrasky commented on Dec 7, 2013
vajraskymannequin
Mannequin
More actions
And don't forget to use self.dirlink instead of os.symlink(src, dst, target_is_directory=True).
Activity
serhiy-storchaka commentedon Dec 4, 2013
Here is a script which success with os.path.realpath(), but fails with pathlib.Path.resolve(). The
readlink -falso success with these examples.pitrou commentedon Dec 4, 2013
This is https://bitbucket.org/pitrou/pathlib/issue/9/pathresolve-fails-on-complex-symlinks
As noted there:
"""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."""
[-]Path.resolve() fails on deep symlinks[/-][+]Path.resolve() ENAMETOOLONG on pathologic symlinks[/+]serhiy-storchaka commentedon Dec 5, 2013
Path.resolve() also fails when last link is absolute.
mkdir testdir
ln -s 0/0 testdir/1
ln -s 1/1 testdir/2
ln -s "$(readlink -f testdir)" testdir/0
Path('testdir/2').resolve() fails:
Here is a patch which implements an algorithm similar to the algorithm used in posixpath.realpath().
vajrasky commentedon Dec 5, 2013
Whoa, Serhiy, your patch won't fly on Windows Vista.
For starter, the patch does not use target_is_directory=True option in os.symlink. It needs that option when creating symlink to the directory on Windows Vista.
The maximum depth that pathlib can do on Windows Vista is 4 (Remember, this line: "for depth in 0, 1, 2, 3, 10, 100"?).
More than that:
OSError: [WinError 1921] The name of the file cannot be resolved by the system:
'C:\\Users\\vajrasky\\Code\\cpython\\@test_4220_tmp\\testdir\\link5'
Not sure whether the bug is in pathlib.py or _getfinalpathname (from nt module).
serhiy-storchaka commentedon Dec 5, 2013
Thank you Vajrasky. Here is a patch with fixed tests.
vajrasky commentedon Dec 5, 2013
It works. Just a coding nitpick, instead of hardcoding os.symlink(src, dst, target_is_directory=True) in the test, you can use helper function in the test itself, self.dirlink.
pitrou commentedon Dec 7, 2013
I would prefer if you made the test simpler. The current setup makes it difficult to understand and reproduce with the command line.
serhiy-storchaka commentedon Dec 7, 2013
How the test can be simpler? It is already simple.
You ca use pathlib_resolve_test.py but replace
os.symlink('.', 'testdir/0')byos.symlink(os.path.abspath('testdir'), 'testdir/0'). Or use following shell commands:mkdir testdir$(seq 100); do ln -s $ ((i-1))/$((i-1)) testdir/$i; done
for i in
ln -s "$(pwd)/testdir" testdir/0
./python -c "import pathlib; print(pathlib.Path('testdir/100').resolve())"
[-]Path.resolve() ENAMETOOLONG on pathologic symlinks[/-][+]Path.resolve() fails on complex symlinks[/+]pitrou commentedon Dec 7, 2013
I mean, don't use loops but a simple test setup as in test_resolve_dot.
I am not interested in the pathologic "100 symlinks" case, just the case where the symlink is absolute.
vajrasky commentedon Dec 7, 2013
And don't forget to use self.dirlink instead of os.symlink(src, dst, target_is_directory=True).
serhiy-storchaka commentedon Dec 7, 2013
Here is a patch with unrolled loops.
pitrou commentedon Dec 16, 2013
I suppose that was some kind of joke, but what I meant was that we don't need to test with 100 levels of symlinks. 2 or 3 are enough...
pitrou commentedon Dec 16, 2013
Here is a patch with refactored tests. Vajrasky, do you want to test under Windows?
serhiy-storchaka commentedon Dec 16, 2013
Yes, sorry for this joke. Your tests LGTM, but why you repeat similar code 3-4 times instead using loops?
vajrasky commentedon Dec 16, 2013
The patch passed on Windows Vista.
pitrou commentedon Dec 16, 2013
For no real reason :) I'll try with a loop.
pitrou commentedon Dec 16, 2013
Ah, I remember. Using subtests would make it more annoying to backport to 2.7.
python-dev commentedon Dec 16, 2013
New changeset 12a52186b4fd by Antoine Pitrou in branch 'default':
Issue bpo-19887: Improve the Path.resolve() algorithm to support certain symlink chains.
http://hg.python.org/cpython/rev/12a52186b4fd
pitrou commentedon Dec 16, 2013
Thanks a lot for the patch!
bluebird75 commentedon Jan 10, 2014
Hi,
This precise set of tests fails on Windows 7 on a NTFS partition (on revision c0b0e7aef360+ tip ), see below.
The problem is probably minor (drive letter case). I won't be able to develop a fix myself, but I'll be happy to test one.
cheers,
Philippe
======================================================================
FAIL: test_complex_symlinks_absolute (test.test_pathlib.PathTest)
----------------------------------------------------------------------
======================================================================
FAIL: test_complex_symlinks_relative (test.test_pathlib.PathTest)
----------------------------------------------------------------------
======================================================================
FAIL: test_complex_symlinks_relative_dot_dot (test.test_pathlib.PathTest)
----------------------------------------------------------------------
======================================================================
FAIL: test_complex_symlinks_absolute (test.test_pathlib.WindowsPathTest)
----------------------------------------------------------------------
======================================================================
FAIL: test_complex_symlinks_relative (test.test_pathlib.WindowsPathTest)
----------------------------------------------------------------------
======================================================================
FAIL: test_complex_symlinks_relative_dot_dot (test.test_pathlib.WindowsPathTest)
----------------------------------------------------------------------
Ran 335 tests in 1.455s
FAILED (failures=6, skipped=93)
test test_pathlib failed
1 test failed:
test_pathlib