summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-11-07 17:50:54 (GMT)
committerChristian Heimes <christian@cheimes.de>2007-11-07 17:50:54 (GMT)
commitcea681be192d9aa9cc33f15f78f3645424a0974f (patch)
tree066d970cf73ffae289a958e2a664db10ffb8d710
parent90b858e1b358f9a55f2178e7f6c81df8a793dc72 (diff)
downloadcpython-cea681be192d9aa9cc33f15f78f3645424a0974f.zip
cpython-cea681be192d9aa9cc33f15f78f3645424a0974f.tar.gz
cpython-cea681be192d9aa9cc33f15f78f3645424a0974f.tar.bz2
Backported fix for bug #1392 from py3k branch r58903.
-rw-r--r--Python/import.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/Python/import.c b/Python/import.c
index e5f7cc6..265afb9 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2978,6 +2978,7 @@ static int
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 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
&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 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
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)) {