This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fixes for bug 940578 (glob.glob on broken symlinks)
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jlgijsbers Nosy List: cben, jlgijsbers
Priority: normal Keywords: patch

Created on 2004-04-24 20:23 by cben, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
glob-minfix.diff cben, 2004-04-24 20:23 Minimal fix to bug 940578
glob-pathfix.diff cben, 2004-04-27 09:27 Proper fix adding `os.path.lexists()`
glob-broken-symlinks.diff jlgijsbers, 2004-08-20 15:39 simpler fix
Messages (7)
msg45830 - (view) Author: Cherniavsky Beni (cben) * Date: 2004-04-24 20:23
This does minimal changes to fix the bug.
It implements a function similar to `os.path.exists()`
but using
`os.lstat()` that doesn't fail on broken symlinks. 
This function would more properly belong in `posix`. 
This patch is good if you want to avoid API changes,
e.g. for backporting the fix.
Test case and doc fix (to make the behavior on broken
symlinks clear) are included.
msg45831 - (view) Author: Cherniavsky Beni (cben) * Date: 2004-04-24 21:25
Logged In: YES 
user_id=36166

The second patch, glob-pathfix.diff, does the right thing by
adding `lexists` to `os.path` - it has no less right to be
there than `exists`.
It's implemented with `os.lstat()` in `posixpath`, alias to
`exists` in other `*path` modules.  **Please verify that
this is sufficient - it seems that no other platfrom has a
`os.lstat` that is not equivallent to `os.stat` but I can't
be sure.**

The glob.py bugfix then is a trivial  change from
``os.path.exists``
to ``os.path.lexists``.
Testcases and doc additions included.
msg45832 - (view) Author: Cherniavsky Beni (cben) * Date: 2004-04-27 09:35
Logged In: YES 
user_id=36166

Uploaded two fixes to glob-pathfix:

- Added ``lexists = exists`` to plat-riscos/riscospath.py
(forgot it previously).

- Switched to implementing `lexists` with `os.lstat` in
macpath.py.  It has a non-trivial `islink`, so it might need
it (or might not; I have no Mac access so I can't tell). 
Better safe than sorry (if somebody knows it's redudadnt,
feel  free to revert to  ``lexists = exists``...).
msg45833 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-20 15:39
Logged In: YES 
user_id=469548

Is there any problem with just using 'if
os.path.islink(pathname) or os.path.exists(pathname)'? It
passes your test and it avoids adding a new function to
os.path. I've attached a patch using this. I'll check it in
if you don't have a problem with this.
msg45834 - (view) Author: Cherniavsky Beni (cben) * Date: 2004-08-21 22:19
Logged In: YES 
user_id=36166

This will indeed fix the bug.  The only technical problem is that it is less efficient (does two stat calls, trying ``lstat(path)`` does one).
The point of adding a new library function was that IMHO it would be no less useful on average than the behavior of `os.path.exists()`.  There must be other code which could benefit from an obvious way to do it.
Also, having two "sister" functions would encourage people to think which behavior for symlinks is more appropriate in their case, instead of automatically using  `os.path.exists()`.
msg45835 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-22 10:55
Logged In: YES 
user_id=469548

Hmm, it _is_ less efficient. I also looked through the
standard library and found another two modules which could
probably use this (tarfile.py and tempfile.py), so lexists
seems mildly useful after all. I'll ask on python-dev for
approval.
msg45836 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-30 10:23
Logged In: YES 
user_id=469548

Well, no problem with python-dev: just checked in
glob-pathfix.diff.
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40187
2004-04-24 20:23:54cbencreate