changeset 4508:0026ccc2bf23

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.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Tue, 05 Jun 2007 19:55:27 -0300
parents 289ec1f36b11
children 9d1380e5c8c5
files mercurial/util.py
diffstat 1 files changed, 2 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- 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)