Rev 19: Don't allow removing a file-id with an active lock. in lp:~jameinel/+junk/file_locking
John Arbash Meinel
john at arbash-meinel.com
Mon Sep 21 20:42:51 BST 2009
At lp:~jameinel/+junk/file_locking
------------------------------------------------------------
revno: 19
revision-id: john at arbash-meinel.com-20090921194240-n7sds4f97u0cnh8t
parent: john at arbash-meinel.com-20090921193948-q2pge6dqzaev52rk
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: file_locking
timestamp: Mon 2009-09-21 14:42:40 -0500
message:
Don't allow removing a file-id with an active lock.
-------------- next part --------------
=== modified file 'file_lock.py'
--- a/file_lock.py 2009-09-21 19:39:48 +0000
+++ b/file_lock.py 2009-09-21 19:42:40 +0000
@@ -206,9 +206,14 @@
del self._active_locks[file_id]
def track(self, file_id):
+ """Include this file-id in the set of objects that can be locked."""
self._tracked_ids.add(file_id)
def stop_tracking(self, file_id):
+ """Remove this file-id from being tracked."""
+ # TODO: Custom exception
+ if file_id in self._active_locks:
+ raise ValueError('{%s} has an active lock' % (file_id,))
self._tracked_ids.remove(file_id)
=== modified file 'tests/test_file_lock.py'
--- a/tests/test_file_lock.py 2009-09-21 19:39:48 +0000
+++ b/tests/test_file_lock.py 2009-09-21 19:42:40 +0000
@@ -161,6 +161,11 @@
self.assertEqual(['file-id-2'], sorted(li._active_locks))
self.assertRaises(KeyError, li.remove_lock, 'file-id-1')
+ def test_stop_tracking_locked(self):
+ li = file_lock.FileLockingInfo(['file-id-1', 'file-id-2'], {})
+ li.create_lock('file-id-1')
+ self.assertRaises(ValueError, li.stop_tracking, 'file-id-1')
+
class TestHeldLockSerializer(tests.TestCase):
More information about the bazaar-commits
mailing list