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.

Author neologix
Recipients neologix, pitrou, rosslagerwall
Date 2012-01-08.16:26:25
SpamBayes Score 3.8301418e-11
Marked as misclassified No
Message-id <1326039986.48.0.995838424483.issue13739@psf.upfronthosting.co.za>
In-reply-to
Content
After a call to fdlistdir(), another call to fdlistdir() on the same file handle (but using a different FD, since the FD passed to fdlistdir() is closed) will return an empty list:

"""
$ cat ~/test_fdlistdir.py 
import os
import sys


fd = os.open(sys.argv[1], os.O_RDONLY)

print(os.fdlistdir(os.dup(fd)))
print(os.fdlistdir(os.dup(fd)))

os.close(fd)
$ ./python ~/test_fdlistdir.py /tmp/
['pulse-B1FebW397VI5', 'ksocket-kdm', 'etc', 'kde-cf', 'ksocket-cf', 'test_posix.py', '.X0-lock', 'kde-kdm', 'akonadi-cf.k6y52j', 'ssh-iSFleEAS1243', '.ICE-unix', '.X11-unix']
[]
"""

That's because fdopendir()/readdir doesn't reset the FD offset.
It's documented by POSIX:
"""
The file offset associated with the file descriptor at the time of the call determines which entries are returned.
"""

That's rather suprising (I got bitten while trying to write a test for #13734).
I see two options:
1. rewind the directory stream in fdlistdir()
2. document this

Here's a patch for option 1.
History
Date User Action Args
2012-01-08 16:26:26neologixsetrecipients: + neologix, pitrou, rosslagerwall
2012-01-08 16:26:26neologixsetmessageid: <1326039986.48.0.995838424483.issue13739@psf.upfronthosting.co.za>
2012-01-08 16:26:25neologixlinkissue13739 messages
2012-01-08 16:26:25neologixcreate