mirror of https://github.com/python/cpython.git
Extracted Windows directory detection from NullImporter.__init__. This greatly simplifies the code and fixes issue6727.
This commit is contained in:
parent
925ff7495b
commit
fa93cf8e3e
|
@ -114,19 +114,34 @@ static const struct filedescr _PyImport_StandardFiletab[] = {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_STAT
|
#ifdef MS_WINDOWS
|
||||||
|
int isdir(char *path) {
|
||||||
|
DWORD rv;
|
||||||
|
/* see issue1293 and issue3677:
|
||||||
|
* stat() on Windows doesn't recognise paths like
|
||||||
|
* "e:\\shared\\" and "\\\\whiterab-c2znlh\\shared" as dirs.
|
||||||
|
* Also reference issue6727:
|
||||||
|
* stat() on Windows is broken and doesn't resolve symlinks properly.
|
||||||
|
*/
|
||||||
|
rv = GetFileAttributesA(path);
|
||||||
|
return rv != INVALID_FILE_ATTRIBUTES && rv & FILE_ATTRIBUTE_DIRECTORY;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#if HAVE_STAT
|
||||||
int isdir(char *path) {
|
int isdir(char *path) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
return stat(path, &statbuf) == 0 && S_ISDIR(statbuf.st_mode);
|
return stat(path, &statbuf) == 0 && S_ISDIR(statbuf.st_mode);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
#ifdef RISCOS
|
||||||
/* with RISCOS, isdir is in unixstuff */
|
/* with RISCOS, isdir is in unixstuff */
|
||||||
#ifndef RISCOS
|
#else
|
||||||
int isdir(char *path) {
|
int isdir(char *path) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* RISCOS */
|
||||||
#endif
|
#endif /* HAVE_STAT */
|
||||||
|
#endif /* MS_WINDOWS */
|
||||||
|
|
||||||
/* Initialize things */
|
/* Initialize things */
|
||||||
|
|
||||||
|
@ -3185,49 +3200,11 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
|
||||||
PyErr_SetString(PyExc_ImportError, "empty pathname");
|
PyErr_SetString(PyExc_ImportError, "empty pathname");
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
#ifndef RISCOS
|
if(isdir(path)) {
|
||||||
#ifndef MS_WINDOWS
|
PyErr_SetString(PyExc_ImportError,
|
||||||
struct stat statbuf;
|
"existing directory");
|
||||||
int rv;
|
return -1;
|
||||||
|
}
|
||||||
rv = stat(path, &statbuf);
|
|
||||||
if (rv == 0) {
|
|
||||||
/* it exists */
|
|
||||||
if (S_ISDIR(statbuf.st_mode)) {
|
|
||||||
/* it's a directory */
|
|
||||||
PyErr_SetString(PyExc_ImportError,
|
|
||||||
"existing directory");
|
|
||||||
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
|
|
||||||
#else /* RISCOS */
|
|
||||||
if (object_exists(path)) {
|
|
||||||
/* it exists */
|
|
||||||
if (isdir(path)) {
|
|
||||||
/* it's a directory */
|
|
||||||
PyErr_SetString(PyExc_ImportError,
|
|
||||||
"existing directory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue