Rev 5600: Fix breaking corrupt lock files on Windows. in http://bazaar.launchpad.net/~jameinel/bzr/2.3-break-lock-corrupt-win32
John Arbash Meinel
john at arbash-meinel.com
Wed Jan 12 20:31:21 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.3-break-lock-corrupt-win32
------------------------------------------------------------
revno: 5600
revision-id: john at arbash-meinel.com-20110112203115-w55rhrojc21qs8tk
parent: pqm at pqm.ubuntu.com-20110112172132-p7n9cxhslpn6svhh
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.3-break-lock-corrupt-win32
timestamp: Wed 2011-01-12 14:31:15 -0600
message:
Fix breaking corrupt lock files on Windows.
We were using transport.get() && transport.delete(), without closing the file.
Switch to using transport.get_bytes(), which closes the file properly.
-------------- next part --------------
=== modified file 'bzrlib/lockdir.py'
--- a/bzrlib/lockdir.py 2010-12-02 10:41:05 +0000
+++ b/bzrlib/lockdir.py 2011-01-12 20:31:15 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006-2010 Canonical Ltd
+# Copyright (C) 2006-2011 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -430,8 +430,8 @@
# there's a small race window between checking it and doing the
# rename.
broken_info_path = tmpname + self.__INFO_NAME
- f = self.transport.get(broken_info_path)
- broken_lines = f.readlines()
+ broken_content = self.transport.get_bytes(broken_info_path)
+ broken_lines = osutils.split_lines(broken_content)
if broken_lines != corrupt_info_lines:
raise LockBreakMismatch(self, broken_lines, corrupt_info_lines)
self.transport.delete(broken_info_path)
=== modified file 'bzrlib/tests/test_lockdir.py'
--- a/bzrlib/tests/test_lockdir.py 2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_lockdir.py 2011-01-12 20:31:15 +0000
@@ -581,16 +581,12 @@
self.prompts.append(('boolean', prompt))
return True
ui = LoggingUIFactory()
- orig_factory = bzrlib.ui.ui_factory
- bzrlib.ui.ui_factory = ui
- try:
- ld2.break_lock()
- self.assertLength(1, ui.prompts)
- self.assertEqual('boolean', ui.prompts[0][0])
- self.assertStartsWith(ui.prompts[0][1], 'Break (corrupt LockDir')
- self.assertRaises(LockBroken, ld.unlock)
- finally:
- bzrlib.ui.ui_factory = orig_factory
+ self.overrideAttr(bzrlib.ui, 'ui_factory', ui)
+ ld2.break_lock()
+ self.assertLength(1, ui.prompts)
+ self.assertEqual('boolean', ui.prompts[0][0])
+ self.assertStartsWith(ui.prompts[0][1], 'Break (corrupt LockDir')
+ self.assertRaises(LockBroken, ld.unlock)
def test_break_lock_missing_info(self):
"""break_lock works even if the info file is missing (and tells the UI
More information about the bazaar-commits
mailing list