diff options
author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-01-23 07:23:03 (GMT) |
---|---|---|
committer | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-01-23 07:23:03 (GMT) |
commit | 21cbf5f896fa4c968b46f05a47c0d59ae6e75938 (patch) | |
tree | 96d054da9450daa1b354804f46d183f6c133ccea /Python/import.c | |
parent | bcd1e3a4538fd64e7928648131c80c3789165889 (diff) | |
download | cpython-21cbf5f896fa4c968b46f05a47c0d59ae6e75938.zip cpython-21cbf5f896fa4c968b46f05a47c0d59ae6e75938.tar.gz cpython-21cbf5f896fa4c968b46f05a47c0d59ae6e75938.tar.bz2 |
Merged revisions 68457 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68457 | kristjan.jonsson | 2009-01-10 05:10:59 +0900 | 1 line
Issue 3677: Fix import from UNC paths on Windows.
........
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/Python/import.c b/Python/import.c index a486383..b79c048 100644 --- a/Python/import.c +++ b/Python/import.c @@ -3233,24 +3233,11 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) PyErr_SetString(PyExc_ImportError, "empty pathname"); return -1; } else { +#ifndef MS_WINDOWS struct stat statbuf; int rv; rv = stat(path, &statbuf); -#ifdef MS_WINDOWS - /* MS Windows stat() chokes on paths like C:\path\. Try to - * recover *one* time by stripping off a trailing slash or - * backslash. http://bugs.python.org/issue1293 - */ - 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); - } -#endif PyMem_Free(path); if (rv == 0) { /* it exists */ @@ -3261,6 +3248,23 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) return -1; } } +#else /* MS_WINDOWS */ + DWORD rv; + /* see issue1293 and issue3677: + * stat() on Windows doesn't recognise paths like + * "e:\\shared\\" and "\\\\whiterab-c2znlh\\shared" as dirs. + */ + rv = GetFileAttributesA(path); + if (rv != INVALID_FILE_ATTRIBUTES) { + /* it exists */ + if (rv & FILE_ATTRIBUTE_DIRECTORY) { + /* it's a directory */ + PyErr_SetString(PyExc_ImportError, + "existing directory"); + return -1; + } + } +#endif } return 0; } |