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
9235b254
Commit
9235b254
authored
Jul 06, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15247: FileIO now raises an error when given a file descriptor pointing to a directory.
parent
01cca5e4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
12 deletions
+16
-12
Lib/test/test_fileio.py
Lib/test/test_fileio.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_io/fileio.c
Modules/_io/fileio.c
+5
-12
No files found.
Lib/test/test_fileio.py
View file @
9235b254
...
...
@@ -127,6 +127,14 @@ class AutoFileTests(unittest.TestCase):
else
:
self
.
fail
(
"Should have raised IOError"
)
@
unittest
.
skipIf
(
os
.
name
==
'nt'
,
"test only works on a POSIX-like system"
)
def
testOpenDirFD
(
self
):
fd
=
os
.
open
(
'.'
,
os
.
O_RDONLY
)
with
self
.
assertRaises
(
IOError
)
as
cm
:
_FileIO
(
fd
,
'r'
)
os
.
close
(
fd
)
self
.
assertEqual
(
cm
.
exception
.
errno
,
errno
.
EISDIR
)
#A set of functions testing that we get expected behaviour if someone has
#manually closed the internal file descriptor. First, a decorator:
def
ClosedFD
(
func
):
...
...
Misc/NEWS
View file @
9235b254
...
...
@@ -87,6 +87,9 @@ Core and Builtins
Library
-------
- Issue #15247: FileIO now raises an error when given a file descriptor
pointing to a directory.
- Issue #5346: Preserve permissions of mbox, MMDF and Babyl mailbox
files on flush().
...
...
Modules/_io/fileio.c
View file @
9235b254
...
...
@@ -166,22 +166,15 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
directories, so we need a check. */
static
int
dircheck
(
fileio
*
self
,
const
char
*
name
)
dircheck
(
fileio
*
self
,
PyObject
*
nameobj
)
{
#if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR)
struct
stat
buf
;
if
(
self
->
fd
<
0
)
return
0
;
if
(
fstat
(
self
->
fd
,
&
buf
)
==
0
&&
S_ISDIR
(
buf
.
st_mode
))
{
char
*
msg
=
strerror
(
EISDIR
);
PyObject
*
exc
;
if
(
internal_close
(
self
))
return
-
1
;
exc
=
PyObject_CallFunction
(
PyExc_IOError
,
"(iss)"
,
EISDIR
,
msg
,
name
);
PyErr_SetObject
(
PyExc_IOError
,
exc
);
Py_XDECREF
(
exc
);
errno
=
EISDIR
;
PyErr_SetFromErrnoWithFilenameObject
(
PyExc_IOError
,
nameobj
);
return
-
1
;
}
#endif
...
...
@@ -373,9 +366,9 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
PyErr_SetFromErrnoWithFilename
(
PyExc_IOError
,
name
);
goto
error
;
}
if
(
dircheck
(
self
,
name
)
<
0
)
goto
error
;
}
if
(
dircheck
(
self
,
nameobj
)
<
0
)
goto
error
;
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
/* don't translate newlines (\r\n <=> \n) */
...
...
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