comparison mercurial/util.py @ 32746:77f354ae1123

util: make filestat.avoidambig() return whether ambiguity is avoided or not
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 09 Jun 2017 12:58:17 +0900
parents 9929af2b09b4
children b5524fd9a4e3
comparison
equal deleted inserted replaced
32745:23734c0e361f 32746:77f354ae1123
1566 """Change file stat of specified path to avoid ambiguity 1566 """Change file stat of specified path to avoid ambiguity
1567 1567
1568 'old' should be previous filestat of 'path'. 1568 'old' should be previous filestat of 'path'.
1569 1569
1570 This skips avoiding ambiguity, if a process doesn't have 1570 This skips avoiding ambiguity, if a process doesn't have
1571 appropriate privileges for 'path'. 1571 appropriate privileges for 'path'. This returns False in this
1572 case.
1573
1574 Otherwise, this returns True, as "ambiguity is avoided".
1572 """ 1575 """
1573 advanced = (old.stat.st_mtime + 1) & 0x7fffffff 1576 advanced = (old.stat.st_mtime + 1) & 0x7fffffff
1574 try: 1577 try:
1575 os.utime(path, (advanced, advanced)) 1578 os.utime(path, (advanced, advanced))
1576 except OSError as inst: 1579 except OSError as inst:
1577 if inst.errno == errno.EPERM: 1580 if inst.errno == errno.EPERM:
1578 # utime() on the file created by another user causes EPERM, 1581 # utime() on the file created by another user causes EPERM,
1579 # if a process doesn't have appropriate privileges 1582 # if a process doesn't have appropriate privileges
1580 return 1583 return False
1581 raise 1584 raise
1585 return True
1582 1586
1583 def __ne__(self, other): 1587 def __ne__(self, other):
1584 return not self == other 1588 return not self == other
1585 1589
1586 class atomictempfile(object): 1590 class atomictempfile(object):