[PATCH 4 of 4] util: extend fspath, search for the file among all files in directory
Simon Heimberg
simohe at besonet.ch
Sat Aug 15 17:06:05 CDT 2009
# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1249671996 -7200
# Node ID d27be8a66806beebe08fd65f50abb980bd7c0a99
# Parent cf5cd700f7d98568cd8e7990888d015c235a4ace
util: extend fspath, search for the file among all files in directory
for finding folded paths. Examples:
- 'Ä' ('A\xcc\x88') for Ä ('\xc3\x84', A umlaut) on hfs
- 'A' for 'A.' on ntfs
tested on linux with vfat
diff -r cf5cd700f7d9 -r d27be8a66806 mercurial/util.py
--- a/mercurial/util.py Mit Jul 29 14:21:18 2009 +0200
+++ b/mercurial/util.py Fre Aug 07 21:06:36 2009 +0200
@@ -658,6 +658,19 @@
result.append(sep)
continue
+ if part in '..':
+ if part == '..':
+ if len(result) >= 2:
+ result.pop()
+ result.pop()
+ else:
+ result.append(part)
+ elif result:
+ result.pop()
+ else:
+ result.append(part)
+ dir = os.path.join(dir, part)
+ continue
if dir not in _fspathcache:
_fspathcache[dir] = os.listdir(dir)
contents = _fspathcache[dir]
@@ -669,8 +682,24 @@
result.append(n)
break
else:
- # Cannot happen, as the file exists!
- result.append(part)
+ # happens on some filesystems (hfs, ntfs)
+ if not hasattr(os.path, 'samestat'):
+ result.append(part)
+ else:
+ st = os.stat(os.path.join(dir,part))
+ for n in contents:
+ try:
+ st2 = os.stat(os.path.join(dir, n))
+ except OSError, e:
+ if e.errno == errno.ENOENT:
+ break
+ raise
+ if st == st2:
+ result.append(n)
+ break
+ else:
+ #should not happen, file existed
+ result.append(part)
dir = os.path.join(dir, lpart)
return ''.join(result)
More information about the Mercurial-devel
mailing list