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

Skip to content

Commit 7961aa6

Browse files
committed
Patch #1197318: Cygwin case-sensitive import patch
A problem regarding importing symlinked modules was recently reported on the Cygwin mailing list: http://cygwin.com/ml/cygwin/2005-04/msg00257.html The following test case demonstrates the problem: $ ls -l total 1 lrwxrwxrwx 1 jt None 6 Apr 23 13:32 bar.py -> foo.py -rw-r--r-- 1 jt None 24 Apr 18 20:13 foo.py $ python -c 'import bar' Traceback (most recent call last): File "<string>", line 1, in ? ImportError: No module named bar Since Cygwin's case_ok() uses a modified version of the Windows's version, the symlinked bar module actually resolves to file foo.py instead of bar.py. This obviously causes the matching code to fail (regardless of case). The patch fixes this problem by making Cygwin use the Mac OS X case_ok() instead of a modified Window's version.
1 parent fffc4b7 commit 7961aa6

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

Python/import.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,16 +1377,13 @@ PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr * fd)
13771377
/* First we may need a pile of platform-specific header files; the sequence
13781378
* of #if's here should match the sequence in the body of case_ok().
13791379
*/
1380-
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
1380+
#if defined(MS_WINDOWS)
13811381
#include <windows.h>
1382-
#ifdef __CYGWIN__
1383-
#include <sys/cygwin.h>
1384-
#endif
13851382

13861383
#elif defined(DJGPP)
13871384
#include <dir.h>
13881385

1389-
#elif defined(__MACH__) && defined(__APPLE__) && defined(HAVE_DIRENT_H)
1386+
#elif (defined(__MACH__) && defined(__APPLE__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)
13901387
#include <sys/types.h>
13911388
#include <dirent.h>
13921389

@@ -1407,23 +1404,15 @@ case_ok(char *buf, int len, int namelen, char *name)
14071404
* match the sequence just above.
14081405
*/
14091406

1410-
/* MS_WINDOWS || __CYGWIN__ */
1411-
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
1407+
/* MS_WINDOWS */
1408+
#if defined(MS_WINDOWS)
14121409
WIN32_FIND_DATA data;
14131410
HANDLE h;
1414-
#ifdef __CYGWIN__
1415-
char tempbuf[MAX_PATH];
1416-
#endif
14171411

14181412
if (Py_GETENV("PYTHONCASEOK") != NULL)
14191413
return 1;
14201414

1421-
#ifdef __CYGWIN__
1422-
cygwin32_conv_to_win32_path(buf, tempbuf);
1423-
h = FindFirstFile(tempbuf, &data);
1424-
#else
14251415
h = FindFirstFile(buf, &data);
1426-
#endif
14271416
if (h == INVALID_HANDLE_VALUE) {
14281417
PyErr_Format(PyExc_NameError,
14291418
"Can't find file for module %.100s\n(filename %.300s)",
@@ -1450,8 +1439,8 @@ case_ok(char *buf, int len, int namelen, char *name)
14501439
}
14511440
return strncmp(ffblk.ff_name, name, namelen) == 0;
14521441

1453-
/* new-fangled macintosh (macosx) */
1454-
#elif defined(__MACH__) && defined(__APPLE__) && defined(HAVE_DIRENT_H)
1442+
/* new-fangled macintosh (macosx) or Cygwin */
1443+
#elif (defined(__MACH__) && defined(__APPLE__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)
14551444
DIR *dirp;
14561445
struct dirent *dp;
14571446
char dirname[MAXPATHLEN + 1];

0 commit comments

Comments
 (0)