Skip to content

Commit b747c0c

Browse files
author
kristjan.jonsson
committed
Issue 3677: Fix import from UNC paths on Windows.
git-svn-id: http://svn.python.org/projects/python/trunk@68457 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent ea10b1f commit b747c0c

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

Python/import.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,24 +3198,11 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
31983198
return -1;
31993199
} else {
32003200
#ifndef RISCOS
3201+
#ifndef MS_WINDOWS
32013202
struct stat statbuf;
32023203
int rv;
32033204

32043205
rv = stat(path, &statbuf);
3205-
#ifdef MS_WINDOWS
3206-
/* MS Windows stat() chokes on paths like C:\path\. Try to
3207-
* recover *one* time by stripping off a trailing slash or
3208-
* backslash. http://bugs.python.org/issue1293
3209-
*/
3210-
if (rv != 0 && pathlen <= MAXPATHLEN &&
3211-
(path[pathlen-1] == '/' || path[pathlen-1] == '\\')) {
3212-
char mangled[MAXPATHLEN+1];
3213-
3214-
strcpy(mangled, path);
3215-
mangled[pathlen-1] = '\0';
3216-
rv = stat(mangled, &statbuf);
3217-
}
3218-
#endif
32193206
if (rv == 0) {
32203207
/* it exists */
32213208
if (S_ISDIR(statbuf.st_mode)) {
@@ -3225,7 +3212,24 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
32253212
return -1;
32263213
}
32273214
}
3228-
#else
3215+
#else /* MS_WINDOWS */
3216+
DWORD rv;
3217+
/* see issue1293 and issue3677:
3218+
* stat() on Windows doesn't recognise paths like
3219+
* "e:\\shared\\" and "\\\\whiterab-c2znlh\\shared" as dirs.
3220+
*/
3221+
rv = GetFileAttributesA(path);
3222+
if (rv != INVALID_FILE_ATTRIBUTES) {
3223+
/* it exists */
3224+
if (rv & FILE_ATTRIBUTE_DIRECTORY) {
3225+
/* it's a directory */
3226+
PyErr_SetString(PyExc_ImportError,
3227+
"existing directory");
3228+
return -1;
3229+
}
3230+
}
3231+
#endif
3232+
#else /* RISCOS */
32293233
if (object_exists(path)) {
32303234
/* it exists */
32313235
if (isdir(path)) {

0 commit comments

Comments
 (0)