Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7546ad32
Commit
7546ad32
authored
Jan 08, 2012
by
Charles-François Natali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #13739: In os.listdir(), rewind the directory stream (so that listdir()
can be called again on the same open file).
parent
94f6fa62
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
2 deletions
+12
-2
Lib/test/test_posix.py
Lib/test/test_posix.py
+10
-2
Modules/posixmodule.c
Modules/posixmodule.c
+2
-0
No files found.
Lib/test/test_posix.py
View file @
7546ad32
...
...
@@ -454,14 +454,22 @@ class PosixTester(unittest.TestCase):
@
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
(
f
1
))
)
# Check the fd was closed by fdlistdir
with
self
.
assertRaises
(
OSError
)
as
ctx
:
posix
.
close
(
f
)
posix
.
close
(
f
1
)
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'
):
...
...
Modules/posixmodule.c
View file @
7546ad32
...
...
@@ -2906,6 +2906,7 @@ posix_fdlistdir(PyObject *self, PyObject *args)
break
;
}
else
{
Py_BEGIN_ALLOW_THREADS
rewinddir
(
dirp
);
closedir
(
dirp
);
Py_END_ALLOW_THREADS
Py_DECREF
(
d
);
...
...
@@ -2929,6 +2930,7 @@ posix_fdlistdir(PyObject *self, PyObject *args)
Py_DECREF
(
v
);
}
Py_BEGIN_ALLOW_THREADS
rewinddir
(
dirp
);
closedir
(
dirp
);
Py_END_ALLOW_THREADS
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment