]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Bug #1524310: Properly report errors from FindNextFile in os.listdir.
authorMartin v. Löwis <martin@v.loewis.de>
Mon, 24 Jul 2006 12:54:17 +0000 (12:54 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Mon, 24 Jul 2006 12:54:17 +0000 (12:54 +0000)
Will backport to 2.4.

Misc/NEWS
Modules/posixmodule.c

index eee36c606d80e4166d0d08e540ff5c70b316f0f0..e721414604eb2f0ea46b11f91a2fad2ed232c99b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.5 release candidate 1?
 Core and builtins
 -----------------
 
+- Bug #1524310: Properly report errors from FindNextFile in os.listdir.
+
 - Patch #1232023: Stop including current directory in search
   path on Windows.
 
index e1182378eebec0367fe9c99150ccbd2b7d78719b..d968b6c4cd4df0e015411edc8745b02eb5bb8728 100644 (file)
@@ -1862,6 +1862,15 @@ posix_listdir(PyObject *self, PyObject *args)
                                Py_BEGIN_ALLOW_THREADS
                                result = FindNextFileW(hFindFile, &wFileData);
                                Py_END_ALLOW_THREADS
+                               /* FindNextFile sets error to ERROR_NO_MORE_FILES if
+                                  it got to the end of the directory. */
+                               if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
+                                   Py_DECREF(d);
+                                   win32_error_unicode("FindNextFileW", wnamebuf);
+                                   FindClose(hFindFile);
+                                   free(wnamebuf);
+                                   return NULL;
+                               }
                        } while (result == TRUE);
 
                        if (FindClose(hFindFile) == FALSE) {
@@ -1921,6 +1930,14 @@ posix_listdir(PyObject *self, PyObject *args)
                Py_BEGIN_ALLOW_THREADS
                result = FindNextFile(hFindFile, &FileData);
                Py_END_ALLOW_THREADS
+               /* FindNextFile sets error to ERROR_NO_MORE_FILES if
+                  it got to the end of the directory. */
+               if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
+                   Py_DECREF(d);
+                   win32_error("FindNextFile", namebuf);
+                   FindClose(hFindFile);
+                   return NULL;
+               }
        } while (result == TRUE);
 
        if (FindClose(hFindFile) == FALSE) {