Remove atomicfile class.
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Tue, 05 Jun 2007 19:55:27 -0300
changeset 4508 0026ccc2bf23
parent 4507 289ec1f36b11
child 4509 9d1380e5c8c5
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.
mercurial/util.py
--- a/mercurial/util.py	Tue Jun 05 19:55:27 2007 -0300
+++ b/mercurial/util.py	Tue Jun 05 19:55:27 2007 -0300
@@ -1195,24 +1195,7 @@
                 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 @@
                 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)