Rev 5331: Add a test to help LockableConfig daughter classes identify methods that needs to be decorated. in file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Jun 30 11:30:44 BST 2010


At file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/

------------------------------------------------------------
revno: 5331
revision-id: v.ladeuil+lp at free.fr-20100630103044-r1tcs4e3y1neyllz
parent: v.ladeuil+lp at free.fr-20100630102933-n8fegp0itijz04jx
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 525571-lock-bazaar-conf-files
timestamp: Wed 2010-06-30 12:30:44 +0200
message:
  Add a test to help LockableConfig daughter classes identify methods that needs to be decorated.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2010-06-30 07:59:52 +0000
+++ b/bzrlib/config.py	2010-06-30 10:30:44 +0000
@@ -519,10 +519,10 @@
         super(LockableConfig, self).__init__(get_filename)
         self.dir = osutils.dirname(osutils.safe_unicode(self._get_filename()))
         self.transport = transport.get_transport(self.dir)
-        self.lock = None
+        self._lock = None
 
     def lock_write(self, token=None):
-        if self.lock is None:
+        if self._lock is None:
             ensure_config_dir_exists(self.dir)
             self._lock = lockdir.LockDir(self.transport, self.lock_name)
         self._lock.lock_write(token)
@@ -534,11 +534,15 @@
     def break_lock(self):
         if not self.transport.has(self.lock_name):
             raise errors.NoLockDir(self.dir)
-        if self.lock is None:
-            self.lock = lockdir.LockDir(self.transport, self.lock_name)
-        self.lock.break_lock()
+        if self._lock is None:
+            self._lock = lockdir.LockDir(self.transport, self.lock_name)
+        self._lock.break_lock()
 
     def _write_config_file(self):
+        if self._lock is None or not self._lock.is_held:
+            # NB: if the following exception is raised it probably means a
+            # missing @needs_write_lock decorator on one of the callers.
+            raise errors.ObjectNotLocked(self)
         fname = self._get_filename()
         f = StringIO()
         p = self._get_parser()

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2010-06-30 07:59:52 +0000
+++ b/bzrlib/tests/test_config.py	2010-06-30 10:30:44 +0000
@@ -450,6 +450,10 @@
         c.set_user_option('one', 'one')
         self.assertEquals('one', c.get_user_option('one'))
 
+    def test_unlocked_config(self):
+        c = self.create_config()
+        self.assertRaises(errors.ObjectNotLocked, c._write_config_file)
+
     def test_listen_to_the_last_speaker(self):
         c1 = self.create_config()
         c2 = self.create_config()



More information about the bazaar-commits mailing list