Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 21cbf5f

Browse files
author
Hirokazu Yamamoto
committed
Merged revisions 68457 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r68457 | kristjan.jonsson | 2009-01-10 05:10:59 +0900 | 1 line Issue 3677: Fix import from UNC paths on Windows. ........
1 parent bcd1e3a commit 21cbf5f

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

Python/import.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,24 +3233,11 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
32333233
PyErr_SetString(PyExc_ImportError, "empty pathname");
32343234
return -1;
32353235
} else {
3236+
#ifndef MS_WINDOWS
32363237
struct stat statbuf;
32373238
int rv;
32383239

32393240
rv = stat(path, &statbuf);
3240-
#ifdef MS_WINDOWS
3241-
/* MS Windows stat() chokes on paths like C:\path\. Try to
3242-
* recover *one* time by stripping off a trailing slash or
3243-
* backslash. http://bugs.python.org/issue1293
3244-
*/
3245-
if (rv != 0 && pathlen <= MAXPATHLEN &&
3246-
(path[pathlen-1] == '/' || path[pathlen-1] == '\\')) {
3247-
char mangled[MAXPATHLEN+1];
3248-
3249-
strcpy(mangled, path);
3250-
mangled[pathlen-1] = '\0';
3251-
rv = stat(mangled, &statbuf);
3252-
}
3253-
#endif
32543241
PyMem_Free(path);
32553242
if (rv == 0) {
32563243
/* it exists */
@@ -3261,6 +3248,23 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
32613248
return -1;
32623249
}
32633250
}
3251+
#else /* MS_WINDOWS */
3252+
DWORD rv;
3253+
/* see issue1293 and issue3677:
3254+
* stat() on Windows doesn't recognise paths like
3255+
* "e:\\shared\\" and "\\\\whiterab-c2znlh\\shared" as dirs.
3256+
*/
3257+
rv = GetFileAttributesA(path);
3258+
if (rv != INVALID_FILE_ATTRIBUTES) {
3259+
/* it exists */
3260+
if (rv & FILE_ATTRIBUTE_DIRECTORY) {
3261+
/* it's a directory */
3262+
PyErr_SetString(PyExc_ImportError,
3263+
"existing directory");
3264+
return -1;
3265+
}
3266+
}
3267+
#endif
32643268
}
32653269
return 0;
32663270
}

0 commit comments

Comments
 (0)