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: glob.glob inconsistent about broken symlinks
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jlgijsbers Nosy List: cben, jlgijsbers, rhettinger
Priority: normal Keywords:

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

Files
File name Uploaded Description Edit
glob-bug.diff cben, 2004-04-23 09:07 Patch to test/test_glob.py that tests for the bug.
Messages (7)
msg20574 - (view) Author: Cherniavsky Beni (cben) * Date: 2004-04-23 09:07
`glob.glob()` uses `os.listdir()`, which includes
borken symlinks in the listing if the pattern contains
shell metacharacters but 
uses `os.path.exists()` which is False for broken
symlinks if the pattern is a fixed name.  Thus:

>>> os.symlink('broken', 'sym1')
>>> os.symlink('broken', 'sym2')
>>> import glob
>>> glob.glob('sym*')
['sym1', 'sym2']
>>> glob.glob('sym1')
[]
>>> glob.glob('sym2')
[]
msg20575 - (view) Author: Cherniavsky Beni (cben) * Date: 2004-04-24 20:32
Logged In: YES 
user_id=36166

This bug exists in all versions of the module since its
creation up to 2.4.

The correct behaviour (judging by the shell's behaviour -
that's the model for the module, isn't it), is to always
include  broken symlinks in the results.

Several fixes for this bug are provided by patch 941486
(http://python.org/sf/941486).  
[They all include the testcase attached here.]
msg20576 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-08-19 17:45
Logged In: YES 
user_id=80475

Did you already fix this one?
msg20577 - (view) Author: Cherniavsky Beni (cben) * Date: 2004-08-20 11:35
Logged In: YES 
user_id=36166

What do you mean?  Patch 941486 is there a long time
already.  Commit it (choose between the minimal fix and the
more proper introduction of `os.path.lexists()`) and it'll
be fixed.
Then you could add patch 943206 if you like ;-).
And I've refreshed both to apply cleanly against current trunk.
msg20578 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-20 15:39
Logged In: YES 
user_id=469548

I think that question was directed at me (Raymond assigned
the bug to me).  Well, I didn't... yet. I've added a comment
to #941486.
msg20579 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-08-20 18:42
Logged In: YES 
user_id=80475

Sorry, my question was meant for Johannes who recently
committed something symlink related.  If his patch did not
fix your issue, he is still the one who will need to review
and apply the patch (I'm on Windows and don't have symlinks).
msg20580 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-30 10:23
Logged In: YES 
user_id=469548

Fixed by applying patch #941486.
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40181
2004-04-23 09:07:31cbencreate