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
{{ message }}
Repository navigation
pathlib.Path.glob causes OSError encountering symlinks to long filenames #87695
Calling pathlib.Path.glob("**/*) on a directory containing a symlink which resolves to a very long filename causes OSError.
This is completely avoidable since symlinks are not followed anyway.
In pathlib.py, the _RecursiveWildcardSelector has a method _iterate_directories which first calls entry.is_dir() prior to excluding based on entry.is_symlink().
It's the entry.is_dir() which is failing.
If the check for entry.is_symlink() were to happen first this error would be avoided.
It's worth noting that on Linux "ls -l bad_link" works fine.
Also "find /some/path/containing/bad/link" works fine.
You do get an error however when running "ls bad_link"
I believe Python's glob() should act like "find" on Linux and not fail.
Because it is explicitly ignoring symlinks anyway, it has no business calling is_dir() on a symlink.
I have attached a file which reproduces this problem. It's meant to be ran inside of an empty directory.
Activity
ericfrederich commentedon Mar 17, 2021
Calling pathlib.Path.glob("**/*) on a directory containing a symlink which resolves to a very long filename causes OSError.
This is completely avoidable since symlinks are not followed anyway.
In pathlib.py, the _RecursiveWildcardSelector has a method _iterate_directories which first calls entry.is_dir() prior to excluding based on entry.is_symlink().
It's the entry.is_dir() which is failing.
If the check for entry.is_symlink() were to happen first this error would be avoided.
It's worth noting that on Linux "ls -l bad_link" works fine.
Also "find /some/path/containing/bad/link" works fine.
You do get an error however when running "ls bad_link"
I believe Python's glob() should act like "find" on Linux and not fail.
Because it is explicitly ignoring symlinks anyway, it has no business calling is_dir() on a symlink.
I have attached a file which reproduces this problem. It's meant to be ran inside of an empty directory.
ericfrederich commentedon Mar 17, 2021
I verified against all versions available for me to select.
For 3.10 I used the 3.10-rc Docker image.
ericfrederich commentedon Mar 19, 2021
I'm happy to create a pull request but would need some help.
Looking at that routine it has changed over time and I cannot simply create a single patch against 3.6 and have it merge cleanly into newer versions.
I'd need help explaining the process
pythonGH-87695: Fix OSError from `pathlib.Path.glob()`
pythonGH-87695: Fix OSError from `pathlib.Path.glob()`
Merge branch 'main' into pythongh-87695-glob-oserror-long-symlink
GH-87695: Fix OSError from `pathlib.Path.glob()` (GH-104292)
pythonGH-87695: Fix OSError from `pathlib.Path.glob()` (pythonGH-104292)
pythonGH-87695: Fix OSError from `pathlib.Path.glob()` (pythonGH-104292)
Merge branch 'main' into fixloadsuperspec
[3.11] GH-87695: Fix OSError from `pathlib.Path.glob()` (GH-104292) (G…
barneygale commentedon May 10, 2023
Fixed in 3.12: #104292 / a33ce66
Backported to 3.11: #104362 / 846a23d
Merge branch 'main' into supermon
encukou commentedon May 23, 2023
Note that this is "fixed" (the error is ignored) in 3.8+ in #79487