348
349
it possibly being still active.
350
351
self._check_not_locked()
351
holder_info = self.peek()
353
holder_info = self.peek()
354
except LockCorrupt, e:
355
# The lock info is corrupt.
356
if bzrlib.ui.ui_factory.get_boolean("Break (corrupt %r)" % (self,)):
357
self.force_break_corrupt(e.file_data)
352
359
if holder_info is not None:
353
360
lock_info = '\n'.join(self._format_lock_info(holder_info))
354
361
if bzrlib.ui.ui_factory.get_boolean("Break %s" % lock_info):
395
402
for hook in self.hooks['lock_broken']:
405
def force_break_corrupt(self, corrupt_info_lines):
406
"""Release a lock that has been corrupted.
408
This is very similar to force_break, it except it doesn't assume that
409
self.peek() can work.
411
:param corrupt_info_lines: the lines of the corrupted info file, used
412
to check that the lock hasn't changed between reading the (corrupt)
413
info file and calling force_break_corrupt.
415
# XXX: this copes with unparseable info files, but what about missing
416
# info files? Or missing lock dirs?
417
self._check_not_locked()
418
tmpname = '%s/broken.%s.tmp' % (self.path, rand_chars(20))
419
self.transport.rename(self._held_dir, tmpname)
420
# check that we actually broke the right lock, not someone else;
421
# there's a small race window between checking it and doing the
423
broken_info_path = tmpname + self.__INFO_NAME
424
f = self.transport.get(broken_info_path)
425
broken_lines = f.readlines()
426
if broken_lines != corrupt_info_lines:
427
raise LockBreakMismatch(self, broken_lines, corrupt_info_lines)
428
self.transport.delete(broken_info_path)
429
self.transport.rmdir(tmpname)
430
result = lock.LockResult(self.transport.abspath(self.path))
431
for hook in self.hooks['lock_broken']:
398
434
def _check_not_locked(self):
399
435
"""If the lock is held by this instance, raise an error."""
400
436
if self._lock_held:
459
495
return s.to_string()
461
497
def _parse_info(self, info_bytes):
462
stanza = rio.read_stanza(osutils.split_lines(info_bytes))
498
lines = osutils.split_lines(info_bytes)
500
stanza = rio.read_stanza(lines)
501
except ValueError, e:
502
mutter('Corrupt lock info file: %r', lines)
503
raise LockCorrupt("could not parse lock info file: " + str(e),
463
505
if stanza is None:
464
506
# see bug 185013; we fairly often end up with the info file being
465
507
# empty after an interruption; we could log a message here but