comparison mercurial/util.py @ 13205:18f0084a97c8

merge with stable
author Matt Mackall <mpm@selenic.com>
date Tue, 28 Dec 2010 13:31:30 -0600
parents 6f011cf52f9a 5b83ab614dab
children 91bc001a592f
comparison
equal deleted inserted replaced
13201:f05250572467 13205:18f0084a97c8
719 except (OSError, AttributeError): 719 except (OSError, AttributeError):
720 return False 720 return False
721 721
722 def checknlink(testfile): 722 def checknlink(testfile):
723 '''check whether hardlink count reporting works properly''' 723 '''check whether hardlink count reporting works properly'''
724 f = testfile + ".hgtmp" 724
725 725 # testfile may be open, so we need a separate file for checking to
726 try: 726 # work around issue2543 (or testfile may get lost on Samba shares)
727 os_link(testfile, f) 727 f1 = testfile + ".hgtmp1"
728 except OSError: 728 if os.path.lexists(f1):
729 return False 729 return False
730 730 try:
731 try: 731 posixfile(f1, 'w').close()
732 except IOError:
733 return False
734
735 f2 = testfile + ".hgtmp2"
736 fd = None
737 try:
738 try:
739 os_link(f1, f2)
740 except OSError:
741 return False
742
732 # nlinks() may behave differently for files on Windows shares if 743 # nlinks() may behave differently for files on Windows shares if
733 # the file is open. 744 # the file is open.
734 fd = open(f) 745 fd = open(f2)
735 return nlinks(f) > 1 746 return nlinks(f2) > 1
736 finally: 747 finally:
737 fd.close() 748 if fd is not None:
738 os.unlink(f) 749 fd.close()
750 for f in (f1, f2):
751 try:
752 os.unlink(f)
753 except OSError:
754 pass
739 755
740 return False 756 return False
741 757
742 def endswithsep(path): 758 def endswithsep(path):
743 '''Check path ends with os.sep or os.altsep.''' 759 '''Check path ends with os.sep or os.altsep.'''