[Pkg-bazaar-commits] ./bzr/unstable r428: - Use AtomicFile to update statcache.

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:19:56 UTC 2009


------------------------------------------------------------
revno: 428
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Tue 2005-05-10 16:00:59 +1000
message:
  - Use AtomicFile to update statcache.
  - New closed property on AtomicFile
modified:
  bzrlib/atomicfile.py
  bzrlib/cache.py
-------------- next part --------------
=== modified file 'bzrlib/atomicfile.py'
--- a/bzrlib/atomicfile.py	2005-05-09 04:59:00 +0000
+++ b/bzrlib/atomicfile.py	2005-05-10 06:00:59 +0000
@@ -39,6 +39,7 @@
         
         self.f = open(self.tmpfilename, mode)
         self.write = self.f.write
+        self.closed = property(f.closed)
 
     def commit(self):
         import sys, os
@@ -53,3 +54,4 @@
         self.f.close()
         os.remove(self.tmpfilename)
         
+        

=== modified file 'bzrlib/cache.py'
--- a/bzrlib/cache.py	2005-05-10 04:50:12 +0000
+++ b/bzrlib/cache.py	2005-05-10 06:00:59 +0000
@@ -18,6 +18,7 @@
 from binascii import b2a_qp, a2b_qp
 
 from trace import mutter
+from errors import BzrError
 
 
 """File stat cache to speed up tree comparisons.
@@ -69,16 +70,19 @@
 
 
 def write_cache(branch, entry_iter):
-    outf = branch.controlfile('work-cache.tmp', 'wt')
-    for entry in entry_iter:
-        outf.write(entry[0] + ' ' + entry[1] + ' ')
-        outf.write(b2a_qp(entry[2], True))
-        outf.write(' %d %d %d %d %d\n' % entry[3:])
-        
-    outf.close()
-    os.rename(branch.controlfilename('work-cache.tmp'),
-              branch.controlfilename('work-cache'))
+    from atomicfile import AtomicFile
+    
+    outf = AtomicFile(branch.controlfilename('work-cache.tmp'), 'wt')
+    try:
+        for entry in entry_iter:
+            outf.write(entry[0] + ' ' + entry[1] + ' ')
+            outf.write(b2a_qp(entry[2], True))
+            outf.write(' %d %d %d %d %d\n' % entry[3:])
 
+        outf.commit()
+    finally:
+        if not outf.closed:
+            outf.abort()
         
         
 def load_cache(branch):



More information about the Pkg-bazaar-commits mailing list