mercurial/util.py
changeset 34079 1104718fb090
parent 34072 30535fe47e78
child 34084 6c5cdb02f2f9
equal deleted inserted replaced
34078:b4b196092cc3 34079:1104718fb090
  1455 def checknlink(testfile):
  1455 def checknlink(testfile):
  1456     '''check whether hardlink count reporting works properly'''
  1456     '''check whether hardlink count reporting works properly'''
  1457 
  1457 
  1458     # testfile may be open, so we need a separate file for checking to
  1458     # testfile may be open, so we need a separate file for checking to
  1459     # work around issue2543 (or testfile may get lost on Samba shares)
  1459     # work around issue2543 (or testfile may get lost on Samba shares)
  1460     f1 = testfile + ".hgtmp1"
  1460     f1, f2, fd = None, None, None
  1461     if os.path.lexists(f1):
       
  1462         return False
       
  1463     try:
  1461     try:
  1464         posixfile(f1, 'w').close()
  1462         fd, f1 = tempfile.mkstemp(prefix='.%s-' % os.path.basename(testfile),
  1465     except IOError:
  1463                                   suffix='1~', dir=os.path.dirname(testfile))
  1466         try:
  1464         os.close(fd)
  1467             os.unlink(f1)
  1465         fd = None
  1468         except OSError:
  1466         f2 = '%s2~' % f1[:-2]
  1469             pass
  1467 
  1470         return False
       
  1471 
       
  1472     f2 = testfile + ".hgtmp2"
       
  1473     fd = None
       
  1474     try:
       
  1475         oslink(f1, f2)
  1468         oslink(f1, f2)
  1476         # nlinks() may behave differently for files on Windows shares if
  1469         # nlinks() may behave differently for files on Windows shares if
  1477         # the file is open.
  1470         # the file is open.
  1478         fd = posixfile(f2)
  1471         fd = posixfile(f2)
  1479         return nlinks(f2) > 1
  1472         return nlinks(f2) > 1
  1482     finally:
  1475     finally:
  1483         if fd is not None:
  1476         if fd is not None:
  1484             fd.close()
  1477             fd.close()
  1485         for f in (f1, f2):
  1478         for f in (f1, f2):
  1486             try:
  1479             try:
  1487                 os.unlink(f)
  1480                 if f is not None:
       
  1481                     os.unlink(f)
  1488             except OSError:
  1482             except OSError:
  1489                 pass
  1483                 pass
  1490 
  1484 
  1491 def endswithsep(path):
  1485 def endswithsep(path):
  1492     '''Check path ends with os.sep or os.altsep.'''
  1486     '''Check path ends with os.sep or os.altsep.'''