[PATCH 1 of 1 STABLE RFC] posix: remove darwin special-casing of realpath (issue3071)

Christian Ebert blacktrash at gmx.net
Sat Oct 29 07:31:57 CDT 2011


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1319891315 -7200
# Branch stable
# Node ID 4339811170f8b29309c4256b14e03c4056866eeb
# Parent  a53888685a6cf3f203caa3a92083f2a80ca66dfe
posix: remove darwin special-casing of realpath (issue3071)

Introduced in 40196d036a71:
"""
The function is implemented for Mac OS X using the F_GETPATH fcntl,
and a basic implementation for Windows is provided as well. On other
POSIX systems, vanilla os.path.realpath() is used.
"""

Remove the darwin workaround as it does wrong thing on darwin,
whereas os.path.realpath does it right.

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -164,42 +164,7 @@
     st2 = os.lstat(fpath2)
     return st1.st_dev == st2.st_dev
 
-if sys.platform == 'darwin':
-    import fcntl # only needed on darwin, missing on jython
-    def realpath(path):
-        '''
-        Returns the true, canonical file system path equivalent to the given
-        path.
-
-        Equivalent means, in this case, resulting in the same, unique
-        file system link to the path. Every file system entry, whether a file,
-        directory, hard link or symbolic link or special, will have a single
-        path preferred by the system, but may allow multiple, differing path
-        lookups to point to it.
-
-        Most regular UNIX file systems only allow a file system entry to be
-        looked up by its distinct path. Obviously, this does not apply to case
-        insensitive file systems, whether case preserving or not. The most
-        complex issue to deal with is file systems transparently reencoding the
-        path, such as the non-standard Unicode normalisation required for HFS+
-        and HFSX.
-        '''
-        # Constants copied from /usr/include/sys/fcntl.h
-        F_GETPATH = 50
-        O_SYMLINK = 0x200000
-
-        try:
-            fd = os.open(path, O_SYMLINK)
-        except OSError, err:
-            if err.errno == errno.ENOENT:
-                return path
-            raise
-
-        try:
-            return fcntl.fcntl(fd, F_GETPATH, '\0' * 1024).rstrip('\0')
-        finally:
-            os.close(fd)
-elif sys.version_info < (2, 4, 2, 'final'):
+if sys.version_info < (2, 4, 2, 'final'):
     # Workaround for http://bugs.python.org/issue1213894 (os.path.realpath
     # didn't resolve symlinks that were the first component of the path.)
     def realpath(path):


More information about the Mercurial-devel mailing list