]> granicus.if.org Git - python/commitdiff
test_glob found a nasty bug in GUSI opendir(): it will not fail when called on files...
authorJack Jansen <jack.jansen@cwi.nl>
Sat, 11 Aug 2001 23:18:55 +0000 (23:18 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Sat, 11 Aug 2001 23:18:55 +0000 (23:18 +0000)
Mac/Modules/macmodule.c

index 7735ab34cd20d5132fc0ee37914cf19dc21c2db8..766722ff016cd42e4363008e8968d3a53a56bcfe 100644 (file)
@@ -311,6 +311,24 @@ mac_listdir(self, args)
        struct dirent *ep;
        if (!PyArg_ParseTuple(args, "s", &name))
                return NULL;
+#ifdef USE_GUSI
+       /* Work around a bug in GUSI: if you opendir() a file it will
+       ** actually opendir() the parent directory.
+       */
+       {
+               struct stat stb;
+               int res;
+               
+               res = stat(name, &stb);
+               if ( res < 0 )
+                       return mac_error();
+               if (!S_ISDIR(stb.st_mode) ) {
+                       errno = ENOTDIR;
+                       return mac_error();
+               }
+       }
+#endif
+               
        Py_BEGIN_ALLOW_THREADS
        if ((dirp = opendir(name)) == NULL) {
                Py_BLOCK_THREADS