Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 4378:e33ad7cea15f
Do not automatically rename an atomicfile if a write to it has generated an exception.
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Wed, 25 Apr 2007 13:14:01 -0700 |
parents | d7ad1e42a368 |
children | f9cd48bd8625 |
comparison
equal
deleted
inserted
replaced
4377:4759da3e4dc8 | 4378:e33ad7cea15f |
---|---|
1159 posixfile.close(self) | 1159 posixfile.close(self) |
1160 | 1160 |
1161 class atomicfile(atomictempfile): | 1161 class atomicfile(atomictempfile): |
1162 """the file will only be copied on close""" | 1162 """the file will only be copied on close""" |
1163 def __init__(self, name, mode): | 1163 def __init__(self, name, mode): |
1164 self._err = False | |
1164 atomictempfile.__init__(self, name, mode) | 1165 atomictempfile.__init__(self, name, mode) |
1166 def write(self, s): | |
1167 try: | |
1168 atomictempfile.write(self, s) | |
1169 except: | |
1170 self._err = True | |
1171 raise | |
1165 def close(self): | 1172 def close(self): |
1166 self.rename() | 1173 self.rename() |
1167 def __del__(self): | 1174 def __del__(self): |
1168 self.rename() | 1175 if not self._err: |
1176 self.rename() | |
1169 | 1177 |
1170 def o(path, mode="r", text=False, atomic=False, atomictemp=False): | 1178 def o(path, mode="r", text=False, atomic=False, atomictemp=False): |
1171 if audit_p: | 1179 if audit_p: |
1172 audit_path(path) | 1180 audit_path(path) |
1173 f = os.path.join(p, path) | 1181 f = os.path.join(p, path) |