~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
347
347
        This is a UI centric function: it uses the bzrlib.ui.ui_factory to
348
348
        prompt for input if a lock is detected and there is any doubt about
349
349
        it possibly being still active.
 
350
 
 
351
        :returns: LockResult for the broken lock.
350
352
        """
351
353
        self._check_not_locked()
352
354
        try:
357
359
                self.force_break_corrupt(e.file_data)
358
360
            return
359
361
        if holder_info is not None:
360
 
            lock_info = '\n'.join(holder_info.to_readable_list())
361
 
            if bzrlib.ui.ui_factory.get_boolean("Break %s" % lock_info):
362
 
                self.force_break(holder_info)
 
362
            info_text = '\n'.join(holder_info.to_readable_list())
 
363
            if bzrlib.ui.ui_factory.confirm_action(
 
364
                "Break %(lock_info)s", 'bzrlib.lockdir.break', 
 
365
                dict(lock_info=info_text)):
 
366
                result = self.force_break(holder_info)
 
367
                bzrlib.ui.ui_factory.show_message(
 
368
                    "Broke lock %s" % result.lock_url)
363
369
 
364
370
    def force_break(self, dead_holder_info):
365
371
        """Release a lock held by another process.
377
383
            to check that it's still held by the same process that the user
378
384
            decided was dead.  If this is not the current holder,
379
385
            LockBreakMismatch is raised.
 
386
 
 
387
        :returns: LockResult for the broken lock.
380
388
        """
381
389
        if not isinstance(dead_holder_info, LockHeldInfo):
382
390
            raise ValueError("dead_holder_info: %r" % dead_holder_info)
402
410
                                 current_info.get('nonce'))
403
411
        for hook in self.hooks['lock_broken']:
404
412
            hook(result)
 
413
        return result
405
414
 
406
415
    def force_break_corrupt(self, corrupt_info_lines):
407
416
        """Release a lock that has been corrupted.
422
431
        # there's a small race window between checking it and doing the
423
432
        # rename.
424
433
        broken_info_path = tmpname + self.__INFO_NAME
425
 
        f = self.transport.get(broken_info_path)
426
 
        broken_lines = f.readlines()
 
434
        broken_content = self.transport.get_bytes(broken_info_path)
 
435
        broken_lines = osutils.split_lines(broken_content)
427
436
        if broken_lines != corrupt_info_lines:
428
437
            raise LockBreakMismatch(self, broken_lines, corrupt_info_lines)
429
438
        self.transport.delete(broken_info_path)