Message335937
When using rglob() to iterate over the files of a directory containing a broken symlink (a link pointing to itself) rglob breaks with "[Errno 40] Too many levels of symbolic links" (OS: Linux).
Steps to reproduce:
mkdir tmp
touch foo
ls -s foo tmp/foo
cd tmp
file foo
foo: broken symbolic link to foo
python3
>>> from pathlib import Path
>>> for f in Path().rglob("*"):
print(x)
foo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/pathlib.py", line 1105, in rglob
for p in selector.select_from(self):
File "/usr/local/lib/python3.8/pathlib.py", line 552, in _select_from
for starting_point in self._iterate_directories(parent_path, is_dir, scandir):
File "/usr/local/lib/python3.8/pathlib.py", line 536, in _iterate_directories
entry_is_dir = entry.is_dir()
OSError: [Errno 40] Too many levels of symbolic links: './foo'
What is more, stat(), is_dir(), is_file() and exists() also do not like those broken links:
>>> Path("foo").is_file()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/pathlib.py", line 1361, in is_file
return S_ISREG(self.stat().st_mode)
File "/usr/local/lib/python3.8/pathlib.py", line 1151, in stat
return self._accessor.stat(self)
OSError: [Errno 40] Too many levels of symbolic links: 'foo'
Is this intended behaviour or is this a bug? I guess it's not intended, since it makes it impossible to iterate over such a directory with rglob(). I could not find anything similar in the bug tracker, but https://bugs.python.org/issue26012 seems to be related.
Tested with Python 3.8.0a1, 3.6.7 and 3.5.2 (OS: Linux Mint 19) |
|
Date |
User |
Action |
Args |
2019-02-19 12:09:57 | Jörg Stucke | set | recipients:
+ Jörg Stucke |
2019-02-19 12:09:57 | Jörg Stucke | set | messageid: <1550578197.02.0.381973172531.issue36035@roundup.psfhosted.org> |
2019-02-19 12:09:56 | Jörg Stucke | link | issue36035 messages |
2019-02-19 12:09:56 | Jörg Stucke | create | |
|