[Pkg-bazaar-commits] ./bzr/unstable r770: - write new working inventory using AtomicFile

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:21:00 UTC 2009


------------------------------------------------------------
revno: 770
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Fri 2005-06-24 19:03:20 +1000
message:
  - write new working inventory using AtomicFile
modified:
  bzrlib/branch.py
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2005-06-24 09:00:35 +0000
+++ b/bzrlib/branch.py	2005-06-24 09:03:20 +0000
@@ -338,16 +338,19 @@
         That is to say, the inventory describing changes underway, that
         will be committed to the next revision.
         """
-        ## TODO: factor out to atomicfile?  is rename safe on windows?
-        ## TODO: Maybe some kind of clean/dirty marker on inventory?
-        tmpfname = self.controlfilename('inventory.tmp')
-        tmpf = file(tmpfname, 'wb')
-        inv.write_xml(tmpf)
-        tmpf.close()
-        inv_fname = self.controlfilename('inventory')
-        if sys.platform == 'win32':
-            os.remove(inv_fname)
-        os.rename(tmpfname, inv_fname)
+        self.lock_write()
+        try:
+            from bzrlib.atomicfile import AtomicFile
+
+            f = AtomicFile(self.controlfilename('inventory'), 'wb')
+            try:
+                inv.write_xml(f)
+                f.commit()
+            finally:
+                f.close()
+        finally:
+            self.unlock()
+        
         mutter('wrote working inventory')
             
 



More information about the Pkg-bazaar-commits mailing list