Rev 5955: (spiv) Fix edge cases in handling interrupts during _rename_in_limbo. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Jun 6 08:07:57 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5955 [merge]
revision-id: pqm at pqm.ubuntu.com-20110606080753-2bf4ydc0czlbusq7
parent: pqm at pqm.ubuntu.com-20110602165709-ry228rc95pgnj3g9
parent: andrew.bennetts at canonical.com-20110602072533-v0pe1ivh27cp0pd8
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-06-06 08:07:53 +0000
message:
(spiv) Fix edge cases in handling interrupts during _rename_in_limbo.
(Andrew Bennetts)
modified:
bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
bzrlib/transform.py transform.py-20060105172343-dd99e54394d91687
=== modified file 'bzrlib/tests/test_transform.py'
--- a/bzrlib/tests/test_transform.py 2011-06-01 08:44:37 +0000
+++ b/bzrlib/tests/test_transform.py 2011-06-02 07:25:33 +0000
@@ -2548,6 +2548,45 @@
self.assertPathDoesNotExist(path)
self.assertPathDoesNotExist(tt._limbodir)
+ def test_rename_in_limbo_rename_raises_after_rename(self):
+ tt, trans_id = self.create_transform_and_root_trans_id()
+ parent1 = tt.new_directory('parent1', tt.root)
+ child1 = tt.new_file('child1', parent1, 'contents')
+ parent2 = tt.new_directory('parent2', tt.root)
+
+ class FakeOSModule(object):
+ def rename(self, old, new):
+ os.rename(old, new)
+ raise RuntimeError
+ self._override_globals_in_method(tt, "_rename_in_limbo",
+ {"os": FakeOSModule()})
+ self.assertRaises(
+ RuntimeError, tt.adjust_path, "child1", parent2, child1)
+ path = osutils.pathjoin(tt._limbo_name(parent2), "child1")
+ self.assertPathExists(path)
+ tt.finalize()
+ self.assertPathDoesNotExist(path)
+ self.assertPathDoesNotExist(tt._limbodir)
+
+ def test_rename_in_limbo_rename_raises_before_rename(self):
+ tt, trans_id = self.create_transform_and_root_trans_id()
+ parent1 = tt.new_directory('parent1', tt.root)
+ child1 = tt.new_file('child1', parent1, 'contents')
+ parent2 = tt.new_directory('parent2', tt.root)
+
+ class FakeOSModule(object):
+ def rename(self, old, new):
+ raise RuntimeError
+ self._override_globals_in_method(tt, "_rename_in_limbo",
+ {"os": FakeOSModule()})
+ self.assertRaises(
+ RuntimeError, tt.adjust_path, "child1", parent2, child1)
+ path = osutils.pathjoin(tt._limbo_name(parent1), "child1")
+ self.assertPathExists(path)
+ tt.finalize()
+ self.assertPathDoesNotExist(path)
+ self.assertPathDoesNotExist(tt._limbodir)
+
class TestTransformMissingParent(tests.TestCaseWithTransport):
=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py 2011-06-01 08:59:17 +0000
+++ b/bzrlib/transform.py 2011-06-02 07:25:33 +0000
@@ -1154,6 +1154,7 @@
self._deletiondir = None
# A mapping of transform ids to their limbo filename
self._limbo_files = {}
+ self._possibly_stale_limbo_files = set()
# A mapping of transform ids to a set of the transform ids of children
# that their limbo directory has
self._limbo_children = {}
@@ -1172,7 +1173,9 @@
if self._tree is None:
return
try:
- limbo_paths = sorted(self._limbo_files.values(), reverse=True)
+ limbo_paths = self._limbo_files.values() + list(
+ self._possibly_stale_limbo_files)
+ limbo_paths = sorted(limbo_paths, reverse=True)
for path in limbo_paths:
try:
delete_any(path)
@@ -1236,11 +1239,14 @@
entries from _limbo_files, because they are now stale.
"""
for trans_id in trans_ids:
- old_path = self._limbo_files.pop(trans_id)
+ old_path = self._limbo_files[trans_id]
+ self._possibly_stale_limbo_files.add(old_path)
+ del self._limbo_files[trans_id]
if trans_id not in self._new_contents:
continue
new_path = self._limbo_name(trans_id)
os.rename(old_path, new_path)
+ self._possibly_stale_limbo_files.remove(old_path)
for descendant in self._limbo_descendants(trans_id):
desc_path = self._limbo_files[descendant]
desc_path = new_path + desc_path[len(old_path):]
More information about the bazaar-commits
mailing list