~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Martin Pool
  • Date: 2011-06-10 07:17:58 UTC
  • mfrom: (5425.6.3 220464-stale-locks)
  • mto: This revision was merged to the branch mainline in revision 5970.
  • Revision ID: mbp@canonical.com-20110610071758-t1ts81zcqx9990yx
Merge checks for username

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
>>> # do something here
93
93
>>> l.unlock()
94
94
 
 
95
Some classes of stale locks can be predicted by checking: the host name is the
 
96
same as the local host name; the user name is the same as the local user; the
 
97
process id no longer exists.  The check on user name is not strictly necessary
 
98
but helps protect against colliding host names.
95
99
"""
96
100
 
97
101
 
402
406
            return
403
407
        if holder_info is not None:
404
408
            if ui.ui_factory.confirm_action(
405
 
                "Break %(lock_info)s",
406
 
                'bzrlib.lockdir.break',
407
 
                dict(lock_info=str(holder_info))):
 
409
                u"Break %(lock_info)s",
 
410
                'locks.confirm_break',
 
411
                dict(lock_info=unicode(holder_info))):
408
412
                result = self.force_break(holder_info)
409
413
                ui.ui_factory.show_message(
410
414
                    "Broke lock %s" % result.lock_url)
805
809
            or cmp(self.info_dict, other.info_dict))
806
810
 
807
811
    def is_locked_by_this_process(self):
808
 
        """Check if the lock appears to be held by this process."""
 
812
        """True if this process seems to be the current lock holder."""
809
813
        return (
810
814
            self.get('hostname') == get_host_name()
811
815
            and self.get('pid') == str(os.getpid())
828
832
        if self.get('hostname') == 'localhost':
829
833
            # Too ambiguous.
830
834
            return False
 
835
        if self.get('user') != get_username_for_lock_info():
 
836
            # Could well be another local process by a different user, but
 
837
            # just to be safe we won't conclude about this either.
 
838
            return False
831
839
        pid_str = self.info_dict.get('pid', None)
832
840
        if not pid_str:
833
841
            mutter("no pid recorded in %r" % (self, ))