~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Karl Bielefeldt
  • Date: 2010-09-29 19:57:28 UTC
  • mto: (5483.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5484.
  • Revision ID: 7mq3cbbd9q@snkmail.com-20100929195728-nvuqlepsrwcxbziw
Use meliae to dump memory to a file upon MemoryError.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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.
352
350
        """
353
351
        self._check_not_locked()
354
352
        try:
363
361
            if bzrlib.ui.ui_factory.confirm_action(
364
362
                "Break %(lock_info)s", 'bzrlib.lockdir.break', 
365
363
                dict(lock_info=lock_info)):
366
 
                result = self.force_break(holder_info)
367
 
                bzrlib.ui.ui_factory.show_message(
368
 
                    "Broke lock %s" % result.lock_url)
 
364
                self.force_break(holder_info)
369
365
 
370
366
    def force_break(self, dead_holder_info):
371
367
        """Release a lock held by another process.
382
378
        After the lock is broken it will not be held by any process.
383
379
        It is possible that another process may sneak in and take the
384
380
        lock before the breaking process acquires it.
385
 
 
386
 
        :returns: LockResult for the broken lock.
387
381
        """
388
382
        if not isinstance(dead_holder_info, dict):
389
383
            raise ValueError("dead_holder_info: %r" % dead_holder_info)
409
403
                                 current_info.get('nonce'))
410
404
        for hook in self.hooks['lock_broken']:
411
405
            hook(result)
412
 
        return result
413
406
 
414
407
    def force_break_corrupt(self, corrupt_info_lines):
415
408
        """Release a lock that has been corrupted.
430
423
        # there's a small race window between checking it and doing the
431
424
        # rename.
432
425
        broken_info_path = tmpname + self.__INFO_NAME
433
 
        broken_content = self.transport.get_bytes(broken_info_path)
434
 
        broken_lines = osutils.split_lines(broken_content)
 
426
        f = self.transport.get(broken_info_path)
 
427
        broken_lines = f.readlines()
435
428
        if broken_lines != corrupt_info_lines:
436
429
            raise LockBreakMismatch(self, broken_lines, corrupt_info_lines)
437
430
        self.transport.delete(broken_info_path)
537
530
            hook(hook_result)
538
531
        return result
539
532
 
540
 
    def lock_url_for_display(self):
541
 
        """Give a nicely-printable representation of the URL of this lock."""
542
 
        # As local lock urls are correct we display them.
543
 
        # We avoid displaying remote lock urls.
544
 
        lock_url = self.transport.abspath(self.path)
545
 
        if lock_url.startswith('file://'):
546
 
            lock_url = lock_url.split('.bzr/')[0]
547
 
        else:
548
 
            lock_url = ''
549
 
        return lock_url
550
 
 
551
533
    def wait_lock(self, timeout=None, poll=None, max_attempts=None):
552
534
        """Wait a certain period for a lock.
553
535
 
577
559
        deadline_str = None
578
560
        last_info = None
579
561
        attempt_count = 0
580
 
        lock_url = self.lock_url_for_display()
581
562
        while True:
582
563
            attempt_count += 1
583
564
            try:
602
583
                if deadline_str is None:
603
584
                    deadline_str = time.strftime('%H:%M:%S',
604
585
                                                 time.localtime(deadline))
 
586
                # As local lock urls are correct we display them.
 
587
                # We avoid displaying remote lock urls.
 
588
                lock_url = self.transport.abspath(self.path)
 
589
                if lock_url.startswith('file://'):
 
590
                    lock_url = lock_url.split('.bzr/')[0]
 
591
                else:
 
592
                    lock_url = ''
605
593
                user, hostname, pid, time_ago = formatted_info
606
594
                msg = ('%s lock %s '        # lock_url
607
595
                    'held by '              # start