Issue 3677: Fix import from UNC paths on Windows.
This commit is contained in:
parent
00f2df495a
commit
3b2a6b819d
|
@ -3198,24 +3198,11 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
#ifndef RISCOS
|
#ifndef RISCOS
|
||||||
|
#ifndef MS_WINDOWS
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
rv = stat(path, &statbuf);
|
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
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
/* it exists */
|
/* it exists */
|
||||||
if (S_ISDIR(statbuf.st_mode)) {
|
if (S_ISDIR(statbuf.st_mode)) {
|
||||||
|
@ -3225,7 +3212,24 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#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
|
||||||
|
#else /* RISCOS */
|
||||||
if (object_exists(path)) {
|
if (object_exists(path)) {
|
||||||
/* it exists */
|
/* it exists */
|
||||||
if (isdir(path)) {
|
if (isdir(path)) {
|
||||||
|
|
Loading…
Reference in New Issue