Changeset 779 for python


Ignore:
Timestamp:
Jun 8, 2016, 10:36:39 PM (9 years ago)
Author:
Yuri Dario
Message:

python: remove 8.3 file name truncation, use opendir() to avoid resolving symlinks. ticket#185.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/trunk/Python/import.c

    r391 r779  
    13031303    static struct filedescr fd_package = {"", "", PKG_DIRECTORY};
    13041304    char *name;
    1305 #if defined(PYOS_OS2)
    1306     size_t saved_len;
    1307     size_t saved_namelen;
    1308     char *saved_buf = NULL;
    1309 #endif
    13101305    if (p_loader != NULL)
    13111306        *p_loader = NULL;
     
    15141509            }
    15151510        }
    1516 #if defined(PYOS_OS2)
    1517         /* take a snapshot of the module spec for restoration
    1518          * after the 8 character DLL hackery
    1519          */
    1520         saved_buf = strdup(buf);
    1521         saved_len = len;
    1522         saved_namelen = namelen;
    1523 #endif /* PYOS_OS2 */
    15241511        for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
    1525 #if defined(PYOS_OS2) && defined(HAVE_DYNAMIC_LOADING)
    1526             /* OS/2 limits DLLs to 8 character names (w/o
    1527                extension)
    1528              * so if the name is longer than that and its a
    1529              * dynamically loaded module we're going to try,
    1530              * truncate the name before trying
    1531              */
    1532             if (strlen(subname) > 8) {
    1533                 /* is this an attempt to load a C extension? */
    1534                 const struct filedescr *scan;
    1535                 scan = _PyImport_DynLoadFiletab;
    1536                 while (scan->suffix != NULL) {
    1537                     if (!strcmp(scan->suffix, fdp->suffix))
    1538                         break;
    1539                     else
    1540                         scan++;
    1541                 }
    1542                 if (scan->suffix != NULL) {
    1543                     /* yes, so truncate the name */
    1544                     namelen = 8;
    1545                     len -= strlen(subname) - namelen;
    1546                     buf[len] = '\0';
    1547                 }
    1548             }
    1549 #endif /* PYOS_OS2 */
    15501512            strcpy(buf+len, fdp->suffix);
    15511513            if (Py_VerboseFlag > 1)
     
    15631525                }
    15641526            }
    1565 #if defined(PYOS_OS2)
    1566             /* restore the saved snapshot */
    1567             strcpy(buf, saved_buf);
    1568             len = saved_len;
    1569             namelen = saved_namelen;
    1570 #endif
    1571         }
    1572 #if defined(PYOS_OS2)
    1573         /* don't need/want the module name snapshot anymore */
    1574         if (saved_buf)
    1575         {
    1576             free(saved_buf);
    1577             saved_buf = NULL;
    1578         }
    1579 #endif
     1527        }
    15801528        Py_XDECREF(copy);
    15811529        if (fp != NULL)
     
    16451593#include <dir.h>
    16461594
    1647 #elif (defined(__MACH__) && defined(__APPLE__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)
     1595#elif (defined(__MACH__) && defined(__APPLE__) || defined(__KLIBC__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)
    16481596#include <sys/types.h>
    16491597#include <dirent.h>
     
    17051653
    17061654/* new-fangled macintosh (macosx) or Cygwin */
    1707 #elif (defined(__MACH__) && defined(__APPLE__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)
     1655/* OS/2 use opendir() because it resolves @unixroot names without resolving symlinks */
     1656#elif (defined(__MACH__) && defined(__APPLE__) || defined(__KLIBC__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)
    17081657    DIR *dirp;
    17091658    struct dirent *dp;
     
    17691718
    17701719    return 0;
    1771 
    1772 /* OS/2 */
    1773 #elif defined(__KLIBC__)
    1774         char canon[MAXPATHLEN+1];
    1775         size_t canonlen;
    1776         char *p, *p2;
    1777 
    1778         if (Py_GETENV("PYTHONCASEOK") != NULL)
    1779                 return 1;
    1780 
    1781         /* This resolves case differences and return and native OS/2
    1782            path. Unfortunately, it'll also resolve symbolic links
    1783            while of course will screw up a bit... */
    1784         if (!_realrealpath(buf, canon, sizeof(canon)))
    1785                 return 0;
    1786         canonlen = strlen(canon);
    1787         if (canonlen < namelen)
    1788                 return 0;
    1789         p = strrchr(canon, SEP);
    1790         p2 = strrchr(p ? p : canon, ALTSEP);
    1791         if (p2)
    1792                 p = p2;
    1793 
    1794         return strncmp(p ? p + 1 : canon, name, namelen) == 0;
    1795 
    1796 #elif defined(PYOS_OS2)
    1797     HDIR hdir = 1;
    1798     ULONG srchcnt = 1;
    1799     FILEFINDBUF3 ffbuf;
    1800     APIRET rc;
    1801 
    1802     if (Py_GETENV("PYTHONCASEOK") != NULL)
    1803         return 1;
    1804 
    1805     rc = DosFindFirst(buf,
    1806                       &hdir,
    1807                       FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY,
    1808                       &ffbuf, sizeof(ffbuf),
    1809                       &srchcnt,
    1810                       FIL_STANDARD);
    1811     if (rc != NO_ERROR)
    1812         return 0;
    1813     return strncmp(ffbuf.achName, name, namelen) == 0;
    18141720
    18151721/* assuming it's a case-sensitive filesystem, so there's nothing to do! */
Note: See TracChangeset for help on using the changeset viewer.