[Python-checkins] cpython: Issue #13739: In os.listdir(), rewind the directory stream (so that listdir()
charles-francois.natali
python-checkins at python.org
Sun Jan 8 18:34:43 CET 2012
http://hg.python.org/cpython/rev/7b2a178c028b
changeset: 74302:7b2a178c028b
user: Charles-François Natali <neologix at free.fr>
date: Sun Jan 08 18:34:06 2012 +0100
summary:
Issue #13739: In os.listdir(), rewind the directory stream (so that listdir()
can be called again on the same open file).
files:
Lib/test/test_posix.py | 12 ++++++++++--
Modules/posixmodule.c | 2 ++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -454,14 +454,22 @@
@unittest.skipUnless(hasattr(posix, 'fdlistdir'), "test needs posix.fdlistdir()")
def test_fdlistdir(self):
f = posix.open(posix.getcwd(), posix.O_RDONLY)
+ self.addCleanup(posix.close, f)
+ f1 = posix.dup(f)
self.assertEqual(
sorted(posix.listdir('.')),
- sorted(posix.fdlistdir(f))
+ sorted(posix.fdlistdir(f1))
)
# Check the fd was closed by fdlistdir
with self.assertRaises(OSError) as ctx:
- posix.close(f)
+ posix.close(f1)
self.assertEqual(ctx.exception.errno, errno.EBADF)
+ # Check that the fd offset was reset (issue #13739)
+ f2 = posix.dup(f)
+ self.assertEqual(
+ sorted(posix.listdir('.')),
+ sorted(posix.fdlistdir(f2))
+ )
def test_access(self):
if hasattr(posix, 'access'):
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2906,6 +2906,7 @@
break;
} else {
Py_BEGIN_ALLOW_THREADS
+ rewinddir(dirp);
closedir(dirp);
Py_END_ALLOW_THREADS
Py_DECREF(d);
@@ -2929,6 +2930,7 @@
Py_DECREF(v);
}
Py_BEGIN_ALLOW_THREADS
+ rewinddir(dirp);
closedir(dirp);
Py_END_ALLOW_THREADS
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list