Rev 28: _get_lock_store() in lp:~jameinel/+junk/file_locking

John Arbash Meinel john at arbash-meinel.com
Tue Sep 22 17:02:43 BST 2009


At lp:~jameinel/+junk/file_locking

------------------------------------------------------------
revno: 28
revision-id: john at arbash-meinel.com-20090922160233-dbl84kieei920hmx
parent: john at arbash-meinel.com-20090921211042-3jviz29epgcs2z13
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: file_locking
timestamp: Tue 2009-09-22 11:02:33 -0500
message:
  _get_lock_store()
-------------- next part --------------
=== modified file 'file_lock.py'
--- a/file_lock.py	2009-09-21 21:09:06 +0000
+++ b/file_lock.py	2009-09-22 16:02:33 +0000
@@ -403,6 +403,7 @@
             except errors.NoSuchFile: # TODO: Custom exception
                 lock_store = FileLockStore.initialize(trans)
                 lock_store.unlock()
+            # TODO: We should support relative paths to lock stores
             conf = self._wt.branch.get_config()
             if conf.get_user_option(self._CONFIG_ENTRY) is not None:
                 raise ValueError('lock store already set.')
@@ -411,6 +412,19 @@
         finally:
             self._wt.unlock()
 
+    def _get_lock_store(self):
+        """Get the lock store, opening it if necessary."""
+        if self._lock_store is None:
+            conf = self._wt.branch.get_config()
+            location = conf.get_user_option(self._CONFIG_ENTRY)
+            if location is None:
+                return None
+            trans = transport.get_transport(location)
+            # This may raise NoSuchFile if the lock store wasn't actually
+            # created. We probably just want a better exception
+            self._lock_store = FileLockStore.open(trans)
+        return self._lock_store
+
     def track(self, path):
         """Start tracking the given path."""
 

=== modified file 'tests/test_file_lock.py'
--- a/tests/test_file_lock.py	2009-09-21 21:10:42 +0000
+++ b/tests/test_file_lock.py	2009-09-22 16:02:33 +0000
@@ -246,6 +246,19 @@
         manager.initialize_lock_store(self.get_transport('lock-store'))
         self.assertFalse(manager.is_tracked(''))
 
+    def test__get_lock_store_open_existing(self):
+        tree, manager = self.make_tree_and_manager('.')
+        manager.initialize_lock_store(self.get_transport('lock-store'))
+        manager = file_lock.FileLockManager(tree)
+        self.assertIs(None, manager._lock_store)
+        store = manager._get_lock_store()
+        self.assertIsNot(None, store)
+        self.assertIs(store, manager._lock_store)
+
+    def test__get_lock_store_none_configured(self):
+        tree, manager = self.make_tree_and_manager('.')
+        self.assertIs(None, manager._get_lock_store())
+
     def test_basic_acceptance(self):
         builder = self.make_branch_builder('path')
         builder.build_snapshot('A', None, [



More information about the bazaar-commits mailing list