]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Bug #1467952: backport: make os.listdir() raise if readdir() fails
authorGeorg Brandl <georg@python.org>
Tue, 11 Apr 2006 06:51:25 +0000 (06:51 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 11 Apr 2006 06:51:25 +0000 (06:51 +0000)
Doc/lib/libos.tex
Misc/NEWS
Modules/posixmodule.c

index f4ec089eebc8a0355f6b90555f91d6f43fd88ab1..89288536b89a250bbf645600b99ef672a13a53b8 100644 (file)
@@ -540,7 +540,8 @@ documentation; flag constants (like \constant{O_RDONLY} and
 This function is intended for low-level I/O.  For normal usage,
 use the built-in function \function{open()}, which returns a ``file
 object'' with \method{read()} and \method{write()} methods (and many
-more).
+more).  To wrap a file descriptor in a ``file object'', use
+\function{fdopen()}.
 \end{notice}
 \end{funcdesc}
 
index cf63a7dd78e071c569fc433b4d0d397ccaa98bf4..e1cf2ef52cea78bc7a270f3fad666963c10a0af4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@ Core and builtins
 Extension Modules
 -----------------
 
+- Bug #1467952: os.listdir() now correctly raises an error if readdir()
+  fails with an error condition.
+
 - Fix bsddb.db.DBError derived exceptions so they can be unpickled.
 
 Library
index e92f69e79fe3ea4eb77ebd68b8f70bdb3eb4cdea..1a514692a0d76491c3f90562501ee988524e9fbe 100644 (file)
@@ -1699,6 +1699,12 @@ posix_listdir(PyObject *self, PyObject *args)
                }
                Py_DECREF(v);
        }
+       if (errno != 0 && d != NULL) {
+               /* readdir() returned NULL and set errno */
+               closedir(dirp);
+               Py_DECREF(d);
+               return posix_error_with_allocated_filename(name); 
+       }
        closedir(dirp);
        PyMem_Free(name);