Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 43791:dfb460004cfe legacy-trunk
Backported fix for bug #1392 from py3k branch r58903.
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Wed, 07 Nov 2007 17:50:54 +0000 |
| parents | 9087337f3a3f |
| children | 2f04abd13394 |
line wrap: on
line diff
--- a/Python/import.c Wed Nov 07 11:57:51 2007 +0000 +++ b/Python/import.c Wed Nov 07 17:50:54 2007 +0000 @@ -2978,6 +2978,7 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) { char *path; + Py_ssize_t pathlen; if (!_PyArg_NoKeywords("NullImporter()", kwds)) return -1; @@ -2986,7 +2987,8 @@ &path)) return -1; - if (strlen(path) == 0) { + pathlen = strlen(path); + if (pathlen == 0) { PyErr_SetString(PyExc_ImportError, "empty pathname"); return -1; } else { @@ -2994,7 +2996,23 @@ struct stat statbuf; int rv; +#ifdef MS_WINDOWS + /* MS Windows' stat chokes on paths like C:\\path\\. Try to + * recover *one* time by stripping of a trailing slash or + * back slash. http://bugs.python.org/issue1293 + */ rv = stat(path, &statbuf); + if (rv != 0 && pathlen <= MAXPATHLEN && + (path[pathlen-1] == '/' || path[pathlen-1] == '\\')) { + char mangled[MAXPATHLEN+1]; + + strcpy(mangled, path); + mangled[pathlen-1] = '\0'; + rv = stat(mangled, &statbuf); + } +#else + rv = stat(path, &statbuf); +#endif if (rv == 0) { /* it exists */ if (S_ISDIR(statbuf.st_mode)) {
