bisect: use proper locking when updating bisect.state
authorMatt Mackall <mpm@selenic.com>
Thu, 27 Dec 2007 23:55:40 -0600
changeset 5738 2a54e2b177b6
parent 5737 6c8df073c3ee
child 5739 45fa7b1c5d4c
bisect: use proper locking when updating bisect.state
hgext/hbisect.py
--- a/hgext/hbisect.py	Thu Dec 27 23:55:40 2007 -0600
+++ b/hgext/hbisect.py	Thu Dec 27 23:55:40 2007 -0600
@@ -132,10 +132,15 @@
         state['skip'].append(node)
 
     # save state
-    f = repo.opener("bisect.state", "w")
-    for kind in state:
-        for node in state[kind]:
-            f.write("%s %s\n" % (kind, hg.hex(node)))
+    f = repo.opener("bisect.state", "w", atomictemp=True)
+    wlock = repo.wlock()
+    try:
+        for kind in state:
+            for node in state[kind]:
+                f.write("%s %s\n" % (kind, hg.hex(node)))
+        f.rename()
+    finally:
+        del wlock
 
     if not state['good'] or not state['bad']:
         return