21 |
21 |
22 if os.name == 'nt': |
22 if os.name == 'nt': |
23 import windows as platform |
23 import windows as platform |
24 else: |
24 else: |
25 import posix as platform |
25 import posix as platform |
|
26 |
|
27 platform.encodinglower = encoding.lower |
|
28 platform.encodingupper = encoding.upper |
26 |
29 |
27 cachestat = platform.cachestat |
30 cachestat = platform.cachestat |
28 checkexec = platform.checkexec |
31 checkexec = platform.checkexec |
29 checklink = platform.checklink |
32 checklink = platform.checklink |
30 copymode = platform.copymode |
33 copymode = platform.copymode |
591 Requires a path (like /foo/.hg) ending with a foldable final |
594 Requires a path (like /foo/.hg) ending with a foldable final |
592 directory component. |
595 directory component. |
593 """ |
596 """ |
594 s1 = os.stat(path) |
597 s1 = os.stat(path) |
595 d, b = os.path.split(path) |
598 d, b = os.path.split(path) |
596 p2 = os.path.join(d, b.upper()) |
599 b2 = b.upper() |
597 if path == p2: |
600 if b == b2: |
598 p2 = os.path.join(d, b.lower()) |
601 b2 = b.lower() |
|
602 if b == b2: |
|
603 return True # no evidence against case sensitivity |
|
604 p2 = os.path.join(d, b2) |
599 try: |
605 try: |
600 s2 = os.stat(p2) |
606 s2 = os.stat(p2) |
601 if s2 == s1: |
607 if s2 == s1: |
602 return False |
608 return False |
603 return True |
609 return True |
609 '''Get name in the case stored in the filesystem |
615 '''Get name in the case stored in the filesystem |
610 |
616 |
611 The name is either relative to root, or it is an absolute path starting |
617 The name is either relative to root, or it is an absolute path starting |
612 with root. Note that this function is unnecessary, and should not be |
618 with root. Note that this function is unnecessary, and should not be |
613 called, for case-sensitive filesystems (simply because it's expensive). |
619 called, for case-sensitive filesystems (simply because it's expensive). |
|
620 |
|
621 Both name and root should be normcase-ed. |
614 ''' |
622 ''' |
615 # If name is absolute, make it relative |
623 # If name is absolute, make it relative |
616 if name.lower().startswith(root.lower()): |
624 if name.startswith(root): |
617 l = len(root) |
625 l = len(root) |
618 if name[l] == os.sep or name[l] == os.altsep: |
626 if name[l] == os.sep or name[l] == os.altsep: |
619 l = l + 1 |
627 l = l + 1 |
620 name = name[l:] |
628 name = name[l:] |
621 |
629 |
626 if os.altsep: |
634 if os.altsep: |
627 seps = seps + os.altsep |
635 seps = seps + os.altsep |
628 # Protect backslashes. This gets silly very quickly. |
636 # Protect backslashes. This gets silly very quickly. |
629 seps.replace('\\','\\\\') |
637 seps.replace('\\','\\\\') |
630 pattern = re.compile(r'([^%s]+)|([%s]+)' % (seps, seps)) |
638 pattern = re.compile(r'([^%s]+)|([%s]+)' % (seps, seps)) |
631 dir = os.path.normcase(os.path.normpath(root)) |
639 dir = os.path.normpath(root) |
632 result = [] |
640 result = [] |
633 for part, sep in pattern.findall(name): |
641 for part, sep in pattern.findall(name): |
634 if sep: |
642 if sep: |
635 result.append(sep) |
643 result.append(sep) |
636 continue |
644 continue |
637 |
645 |
638 if dir not in _fspathcache: |
646 if dir not in _fspathcache: |
639 _fspathcache[dir] = os.listdir(dir) |
647 _fspathcache[dir] = os.listdir(dir) |
640 contents = _fspathcache[dir] |
648 contents = _fspathcache[dir] |
641 |
649 |
642 lpart = part.lower() |
|
643 lenp = len(part) |
650 lenp = len(part) |
644 for n in contents: |
651 for n in contents: |
645 if lenp == len(n) and n.lower() == lpart: |
652 if lenp == len(n) and normcase(n) == part: |
646 result.append(n) |
653 result.append(n) |
647 break |
654 break |
648 else: |
655 else: |
649 # Cannot happen, as the file exists! |
656 # Cannot happen, as the file exists! |
650 result.append(part) |
657 result.append(part) |
651 dir = os.path.join(dir, lpart) |
658 dir = os.path.join(dir, part) |
652 |
659 |
653 return ''.join(result) |
660 return ''.join(result) |
654 |
661 |
655 def checknlink(testfile): |
662 def checknlink(testfile): |
656 '''check whether hardlink count reporting works properly''' |
663 '''check whether hardlink count reporting works properly''' |