~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: John Arbash Meinel
  • Date: 2010-02-17 17:11:16 UTC
  • mfrom: (4797.2.17 2.1)
  • mto: (4797.2.18 2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: john@arbash-meinel.com-20100217171116-h7t9223ystbnx5h8
merge bzr.2.1 in preparation for NEWS entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008 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
110
110
    debug,
111
111
    errors,
112
112
    lock,
 
113
    osutils,
113
114
    )
114
115
import bzrlib.config
115
116
from bzrlib.decorators import only_raises
241
242
        # incorrect.  It's possible some other servers or filesystems will
242
243
        # have a similar bug allowing someone to think they got the lock
243
244
        # when it's already held.
 
245
        #
 
246
        # See <https://bugs.edge.launchpad.net/bzr/+bug/498378> for one case.
 
247
        #
 
248
        # Strictly the check is unnecessary and a waste of time for most
 
249
        # people, but probably worth trapping if something is wrong.
244
250
        info = self.peek()
245
251
        self._trace("after locking, info=%r", info)
 
252
        if info is None:
 
253
            raise LockFailed(self, "lock was renamed into place, but "
 
254
                "now is missing!")
246
255
        if info['nonce'] != self.nonce:
247
256
            self._trace("rename succeeded, "
248
257
                "but lock is still held by someone else")
416
425
 
417
426
        peek() reads the info file of the lock holder, if any.
418
427
        """
419
 
        return self._parse_info(self.transport.get(path))
 
428
        return self._parse_info(self.transport.get_bytes(path))
420
429
 
421
430
    def peek(self):
422
431
        """Check if the lock is held by anyone.
449
458
                   )
450
459
        return s.to_string()
451
460
 
452
 
    def _parse_info(self, info_file):
453
 
        return rio.read_stanza(info_file.readlines()).as_dict()
 
461
    def _parse_info(self, info_bytes):
 
462
        # TODO: Handle if info_bytes is empty
 
463
        return rio.read_stanza(osutils.split_lines(info_bytes)).as_dict()
454
464
 
455
465
    def attempt_lock(self):
456
466
        """Take the lock; fail if it's already held.
524
534
                    deadline_str = time.strftime('%H:%M:%S',
525
535
                                                 time.localtime(deadline))
526
536
                lock_url = self.transport.abspath(self.path)
 
537
                # See <https://bugs.edge.launchpad.net/bzr/+bug/250451>
 
538
                # the URL here is sometimes not one that is useful to the
 
539
                # user, perhaps being wrapped in a lp-%d or chroot decorator,
 
540
                # especially if this error is issued from the server.
527
541
                self._report_function('%s %s\n'
528
 
                                      '%s\n' # held by
529
 
                                      '%s\n' # locked ... ago
530
 
                                      'Will continue to try until %s, unless '
531
 
                                      'you press Ctrl-C\n'
532
 
                                      'If you\'re sure that it\'s not being '
533
 
                                      'modified, use bzr break-lock %s',
534
 
                                      start,
535
 
                                      formatted_info[0],
536
 
                                      formatted_info[1],
537
 
                                      formatted_info[2],
538
 
                                      deadline_str,
539
 
                                      lock_url)
 
542
                    '%s\n' # held by
 
543
                    '%s\n' # locked ... ago
 
544
                    'Will continue to try until %s, unless '
 
545
                    'you press Ctrl-C.\n'
 
546
                    'See "bzr help break-lock" for more.',
 
547
                    start,
 
548
                    formatted_info[0],
 
549
                    formatted_info[1],
 
550
                    formatted_info[2],
 
551
                    deadline_str,
 
552
                    )
540
553
 
541
554
            if (max_attempts is not None) and (attempt_count >= max_attempts):
542
555
                self._trace("exceeded %d attempts")