comparison mercurial/posix.py @ 20202:a6014018ec28

util: remove unused realpath (issue4063) util.realpath was in use for only 5 days from dbdb777502dc until it was backed out in c519cd8f0169 because it caused issue3077 and issue3071.
author Christian Ebert <blacktrash@gmx.net>
date Sun, 29 Dec 2013 13:54:04 +0000
parents cfdae231ba78
children 234e4c24b980
comparison
equal deleted inserted replaced
20201:bc3b48b0f5c8 20202:a6014018ec28
195 # os.path.normcase is a no-op, which doesn't help us on non-native filesystems 195 # os.path.normcase is a no-op, which doesn't help us on non-native filesystems
196 def normcase(path): 196 def normcase(path):
197 return path.lower() 197 return path.lower()
198 198
199 if sys.platform == 'darwin': 199 if sys.platform == 'darwin':
200 import fcntl # only needed on darwin, missing on jython
201 200
202 def normcase(path): 201 def normcase(path):
203 ''' 202 '''
204 Normalize a filename for OS X-compatible comparison: 203 Normalize a filename for OS X-compatible comparison:
205 - escape-encode invalid characters 204 - escape-encode invalid characters
263 u = s.decode('utf-8') 262 u = s.decode('utf-8')
264 263
265 # Decompose then lowercase (HFS+ technote specifies lower) 264 # Decompose then lowercase (HFS+ technote specifies lower)
266 return unicodedata.normalize('NFD', u).lower().encode('utf-8') 265 return unicodedata.normalize('NFD', u).lower().encode('utf-8')
267 266
268 def realpath(path):
269 '''
270 Returns the true, canonical file system path equivalent to the given
271 path.
272
273 Equivalent means, in this case, resulting in the same, unique
274 file system link to the path. Every file system entry, whether a file,
275 directory, hard link or symbolic link or special, will have a single
276 path preferred by the system, but may allow multiple, differing path
277 lookups to point to it.
278
279 Most regular UNIX file systems only allow a file system entry to be
280 looked up by its distinct path. Obviously, this does not apply to case
281 insensitive file systems, whether case preserving or not. The most
282 complex issue to deal with is file systems transparently reencoding the
283 path, such as the non-standard Unicode normalisation required for HFS+
284 and HFSX.
285 '''
286 # Constants copied from /usr/include/sys/fcntl.h
287 F_GETPATH = 50
288 O_SYMLINK = 0x200000
289
290 try:
291 fd = os.open(path, O_SYMLINK)
292 except OSError, err:
293 if err.errno == errno.ENOENT:
294 return path
295 raise
296
297 try:
298 return fcntl.fcntl(fd, F_GETPATH, '\0' * 1024).rstrip('\0')
299 finally:
300 os.close(fd)
301 elif sys.version_info < (2, 4, 2, 'final'):
302 # Workaround for http://bugs.python.org/issue1213894 (os.path.realpath
303 # didn't resolve symlinks that were the first component of the path.)
304 def realpath(path):
305 if os.path.isabs(path):
306 return os.path.realpath(path)
307 else:
308 return os.path.realpath('./' + path)
309 else:
310 # Fallback to the likely inadequate Python builtin function.
311 realpath = os.path.realpath
312
313 if sys.platform == 'cygwin': 267 if sys.platform == 'cygwin':
314 # workaround for cygwin, in which mount point part of path is 268 # workaround for cygwin, in which mount point part of path is
315 # treated as case sensitive, even though underlying NTFS is case 269 # treated as case sensitive, even though underlying NTFS is case
316 # insensitive. 270 # insensitive.
317 271