obsolete: improve locking when writing obsolete data
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Sat, 07 Jan 2012 11:26:48 +0100
changeset 121 7280eede21ea
parent 120 ba45bb2d35cb
child 122 c75a73209f1e
obsolete: improve locking when writing obsolete data
hgext/obsolete.py
--- a/hgext/obsolete.py	Sat Jan 07 11:20:59 2012 +0100
+++ b/hgext/obsolete.py	Sat Jan 07 11:26:48 2012 +0100
@@ -387,15 +387,19 @@
         def _writeobsrels(self):
             """Write obsolete relation on disk"""
             # XXX handle lock
-            f = self.opener('obsolete-relations', 'w', atomictemp=True)
+            lock = self.wlock()
             try:
-                _obsserialise(self._obssubrels, f)
+                f = self.opener('obsolete-relations', 'w', atomictemp=True)
                 try:
-                    f.rename()
-                except AttributeError: # old version
+                    _obsserialise(self._obssubrels, f)
+                    try:
+                        f.rename()
+                    except AttributeError: # old version
+                        f.close()
+                finally:
                     f.close()
             finally:
-                f.close()
+                lock.release()
 
         ### local clone support