243
243
# have a similar bug allowing someone to think they got the lock
244
244
# when it's already held.
246
# See <https://bugs.edge.launchpad.net/bzr/+bug/498378> for one case.
246
# See <https://bugs.launchpad.net/bzr/+bug/498378> for one case.
248
248
# Strictly the check is unnecessary and a waste of time for most
249
249
# people, but probably worth trapping if something is wrong.
351
351
holder_info = self.peek()
352
352
if holder_info is not None:
353
353
lock_info = '\n'.join(self._format_lock_info(holder_info))
354
if bzrlib.ui.ui_factory.get_boolean("Break %s" % lock_info):
354
if bzrlib.ui.ui_factory.confirm_action(
355
"Break %(lock_info)s", 'bzrlib.lockdir.break',
356
dict(lock_info=lock_info)):
355
357
self.force_break(holder_info)
357
359
def force_break(self, dead_holder_info):
447
449
# XXX: is creating this here inefficient?
448
450
config = bzrlib.config.GlobalConfig()
450
user = config.user_email()
451
except errors.NoEmailInUsername:
452
452
user = config.username()
453
except errors.NoWhoami:
454
user = osutils.getuser_unicode()
453
455
s = rio.Stanza(hostname=get_host_name(),
454
456
pid=str(os.getpid()),
455
457
start_time=str(int(time.time())),
539
541
if deadline_str is None:
540
542
deadline_str = time.strftime('%H:%M:%S',
541
543
time.localtime(deadline))
544
# As local lock urls are correct we display them.
545
# We avoid displaying remote lock urls.
542
546
lock_url = self.transport.abspath(self.path)
543
# See <https://bugs.edge.launchpad.net/bzr/+bug/250451>
544
# the URL here is sometimes not one that is useful to the
545
# user, perhaps being wrapped in a lp-%d or chroot decorator,
546
# especially if this error is issued from the server.
547
self._report_function('%s %s\n'
549
'%s\n' # locked ... ago
550
'Will continue to try until %s, unless '
551
'you press Ctrl-C.\n'
552
'See "bzr help break-lock" for more.',
547
if lock_url.startswith('file://'):
548
lock_url = lock_url.split('.bzr/')[0]
551
user, hostname, pid, time_ago = formatted_info
552
msg = ('%s lock %s ' # lock_url
556
'[process #%s], ' # pid
557
'acquired %s.') # time ago
558
msg_args = [start, lock_url, user, hostname, pid, time_ago]
560
msg += ('\nWill continue to try until %s, unless '
562
msg_args.append(deadline_str)
563
msg += '\nSee "bzr help break-lock" for more.'
564
self._report_function(msg, *msg_args)
560
565
if (max_attempts is not None) and (attempt_count >= max_attempts):
561
566
self._trace("exceeded %d attempts")
562
567
raise LockContention(self)
564
569
self._trace("waiting %ss", poll)
572
# As timeout is always 0 for remote locks
573
# this block is applicable only for local
567
575
self._trace("timeout after waiting %ss", timeout)
568
raise LockContention(self)
576
raise LockContention('(local)', lock_url)
570
578
def leave_in_place(self):
571
579
self._locked_via_token = True
617
625
def _format_lock_info(self, info):
618
626
"""Turn the contents of peek() into something for the user"""
619
lock_url = self.transport.abspath(self.path)
620
627
start_time = info.get('start_time')
621
628
if start_time is None:
622
629
time_ago = '(unknown)'
624
631
time_ago = format_delta(time.time() - int(info['start_time']))
632
user = info.get('user', '<unknown>')
633
hostname = info.get('hostname', '<unknown>')
634
pid = info.get('pid', '<unknown>')
626
'lock %s' % (lock_url,),
627
'held by %s on host %s [process #%s]' %
628
tuple([info.get(x, '<unknown>') for x in ['user', 'hostname', 'pid']]),
629
'locked %s' % (time_ago,),
632
642
def validate_token(self, token):