Mercurial > hg
changeset 4331:ce52deed83bc
atomicfile: don't copy the original file if it'll be truncated
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Mon, 09 Apr 2007 04:24:17 -0300 |
parents | 1b9fc3f48861 |
children | 4e5e1638b165 |
files | mercurial/util.py |
diffstat | 1 files changed, 4 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/util.py Mon Apr 09 04:24:17 2007 -0300 +++ b/mercurial/util.py Mon Apr 09 04:24:17 2007 -0300 @@ -1005,7 +1005,7 @@ p = base audit_p = audit - def mktempcopy(name): + def mktempcopy(name, emptyok=False): d, fn = os.path.split(name) fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d) os.close(fd) @@ -1019,6 +1019,8 @@ raise st_mode = 0666 & ~_umask os.chmod(temp, st_mode) + if emptyok: + return temp try: try: ifp = posixfile(name, "rb") @@ -1043,7 +1045,7 @@ """the file will only be copied when rename is called""" def __init__(self, name, mode): self.__name = name - self.temp = mktempcopy(name) + self.temp = mktempcopy(name, emptyok=('w' in mode)) posixfile.__init__(self, self.temp, mode) def rename(self): if not self.closed: