##// END OF EJS Templates
filestat: move __init__ to frompath constructor...
Siddharth Agarwal -
r32772:7ad95626 default
parent child Browse files
Show More
@@ -432,7 +432,8 b' class dirstate(object):'
432 432 self._map = {}
433 433 self._copymap = {}
434 434 # ignore HG_PENDING because identity is used only for writing
435 self._identity = util.filestat(self._opener.join(self._filename))
435 self._identity = util.filestat.frompath(
436 self._opener.join(self._filename))
436 437 try:
437 438 fp = self._opendirstatefile()
438 439 try:
@@ -1098,7 +1098,7 b' def copyfile(src, dest, hardlink=False, '
1098 1098 oldstat = None
1099 1099 if os.path.lexists(dest):
1100 1100 if checkambig:
1101 oldstat = checkambig and filestat(dest)
1101 oldstat = checkambig and filestat.frompath(dest)
1102 1102 unlink(dest)
1103 1103 if hardlink:
1104 1104 # Hardlinks are problematic on CIFS (issue4546), do not allow hardlinks
@@ -1128,7 +1128,7 b' def copyfile(src, dest, hardlink=False, '
1128 1128 else:
1129 1129 shutil.copymode(src, dest)
1130 1130 if oldstat and oldstat.stat:
1131 newstat = filestat(dest)
1131 newstat = filestat.frompath(dest)
1132 1132 if newstat.isambig(oldstat):
1133 1133 # stat of copied file is ambiguous to original one
1134 1134 advanced = (oldstat.stat.st_mtime + 1) & 0x7fffffff
@@ -1506,13 +1506,18 b' class filestat(object):'
1506 1506 exists. Otherwise, it is None. This can avoid preparative
1507 1507 'exists()' examination on client side of this class.
1508 1508 """
1509 def __init__(self, path):
1509 def __init__(self, stat):
1510 self.stat = stat
1511
1512 @classmethod
1513 def frompath(cls, path):
1510 1514 try:
1511 self.stat = os.stat(path)
1515 stat = os.stat(path)
1512 1516 except OSError as err:
1513 1517 if err.errno != errno.ENOENT:
1514 1518 raise
1515 self.stat = None
1519 stat = None
1520 return cls(stat)
1516 1521
1517 1522 __hash__ = object.__hash__
1518 1523
@@ -1622,10 +1627,10 b' class atomictempfile(object):'
1622 1627 if not self._fp.closed:
1623 1628 self._fp.close()
1624 1629 filename = localpath(self.__name)
1625 oldstat = self._checkambig and filestat(filename)
1630 oldstat = self._checkambig and filestat.frompath(filename)
1626 1631 if oldstat and oldstat.stat:
1627 1632 rename(self._tempname, filename)
1628 newstat = filestat(filename)
1633 newstat = filestat.frompath(filename)
1629 1634 if newstat.isambig(oldstat):
1630 1635 # stat of changed file is ambiguous to original one
1631 1636 advanced = (oldstat.stat.st_mtime + 1) & 0x7fffffff
@@ -176,11 +176,11 b' class abstractvfs(object):'
176 176 """
177 177 srcpath = self.join(src)
178 178 dstpath = self.join(dst)
179 oldstat = checkambig and util.filestat(dstpath)
179 oldstat = checkambig and util.filestat.frompath(dstpath)
180 180 if oldstat and oldstat.stat:
181 181 def dorename(spath, dpath):
182 182 ret = util.rename(spath, dpath)
183 newstat = util.filestat(dpath)
183 newstat = util.filestat.frompath(dpath)
184 184 if newstat.isambig(oldstat):
185 185 # stat of renamed file is ambiguous to original one
186 186 return ret, newstat.avoidambig(dpath, oldstat)
@@ -625,12 +625,12 b' class checkambigatclosing(closewrapbase)'
625 625 """
626 626 def __init__(self, fh):
627 627 super(checkambigatclosing, self).__init__(fh)
628 object.__setattr__(self, r'_oldstat', util.filestat(fh.name))
628 object.__setattr__(self, r'_oldstat', util.filestat.frompath(fh.name))
629 629
630 630 def _checkambig(self):
631 631 oldstat = self._oldstat
632 632 if oldstat.stat:
633 newstat = util.filestat(self._origfh.name)
633 newstat = util.filestat.frompath(self._origfh.name)
634 634 if newstat.isambig(oldstat):
635 635 # stat of changed file is ambiguous to original one
636 636 newstat.avoidambig(self._origfh.name, oldstat)
General Comments 0
You need to be logged in to leave comments. Login now