# HG changeset patch # User Alexis S. L. Carvalho # Date 2007-06-05 22:55:27 # Node ID 0026ccc2bf23ab06889e3668a4771787cabf1ee6 # Parent 289ec1f36b111574f7a179de9ec916c1d7a7ac02 Remove atomicfile class. The interface provided by opener(atomic=True) is inherently unsafe: if an exception is raised in the code using the atomic file, the possibly incomplete file will be renamed to its final destination, defeating the whole purpose of atomic files. To get around this, we would either need some bad hacks involving sys.exc_info (to make sure things work in except: blocks), or an interface to say "file is complete; rename it". This is the exact interface provided by atomictempfile. Since there are no remaining users of the atomicfile class, just remove it. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1195,24 +1195,7 @@ def opener(base, audit=True): except: pass posixfile.close(self) - class atomicfile(atomictempfile): - """the file will only be copied on close""" - def __init__(self, name, mode): - self._err = False - atomictempfile.__init__(self, name, mode) - def write(self, s): - try: - atomictempfile.write(self, s) - except: - self._err = True - raise - def close(self): - self.rename() - def __del__(self): - if not self._err: - self.rename() - - def o(path, mode="r", text=False, atomic=False, atomictemp=False): + def o(path, mode="r", text=False, atomictemp=False): if audit_p: audit_path(path) f = os.path.join(p, path) @@ -1228,9 +1211,7 @@ def opener(base, audit=True): d = os.path.dirname(f) if not os.path.isdir(d): os.makedirs(d) - if atomic: - return atomicfile(f, mode) - elif atomictemp: + if atomictemp: return atomictempfile(f, mode) if nlink > 1: rename(mktempcopy(f), f)