[Patches] [ python-Patches-941486 ] Fixes for bug 940578 (glob.glob on broken symlinks)

SourceForge.net noreply at sourceforge.net
Sun Aug 22 00:19:25 CEST 2004


Patches item #941486, was opened at 2004-04-24 23:23
Message generated for change (Comment added) made by cben
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=941486&group_id=5470

Category: Library (Lib)
Group: Python 2.2.x
Status: Open
Resolution: None
Priority: 5
Submitted By: Cherniavsky Beni (cben)
Assigned to: Johannes Gijsbers (jlgijsbers)
Summary: Fixes for bug 940578 (glob.glob on broken symlinks)

Initial Comment:
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.


----------------------------------------------------------------------

>Comment By: Cherniavsky Beni (cben)
Date: 2004-08-22 01:19

Message:
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()`.

----------------------------------------------------------------------

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-08-20 18:39

Message:
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.

----------------------------------------------------------------------

Comment By: Cherniavsky Beni (cben)
Date: 2004-04-27 12:35

Message:
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``...).

----------------------------------------------------------------------

Comment By: Cherniavsky Beni (cben)
Date: 2004-04-25 00:25

Message:
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.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=941486&group_id=5470


More information about the Patches mailing list