summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2009-01-09 20:10:59 (GMT)
committerKristján Valur Jónsson <kristjan@ccpgames.com>2009-01-09 20:10:59 (GMT)
commit3b2a6b819d93868c960da91aeebca7093d6f1627 (patch)
tree16e83a453f2418b982d5daa5e14f8648eb2b7f49 /Python
parent00f2df495a6fcb40d70243c34f296f26ccc72719 (diff)
downloadcpython-3b2a6b819d93868c960da91aeebca7093d6f1627.zip
cpython-3b2a6b819d93868c960da91aeebca7093d6f1627.tar.gz
cpython-3b2a6b819d93868c960da91aeebca7093d6f1627.tar.bz2
Issue 3677: Fix import from UNC paths on Windows.
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/Python/import.c b/Python/import.c
index e9ff922..b00986c 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -3198,24 +3198,11 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
return -1;
} else {
#ifndef RISCOS
+#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
if (rv == 0) {
/* it exists */
if (S_ISDIR(statbuf.st_mode)) {
@@ -3225,7 +3212,24 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
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)) {
/* it exists */
if (isdir(path)) {