~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Jelmer Vernooij
  • Date: 2009-10-27 21:54:26 UTC
  • mfrom: (4771 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4833.
  • Revision ID: jelmer@samba.org-20091027215426-72164bkd4mq9dsd4
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 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,
114
113
    )
115
114
import bzrlib.config
116
115
from bzrlib.decorators import only_raises
242
241
        # incorrect.  It's possible some other servers or filesystems will
243
242
        # have a similar bug allowing someone to think they got the lock
244
243
        # 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.
250
244
        info = self.peek()
251
245
        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!")
255
246
        if info['nonce'] != self.nonce:
256
247
            self._trace("rename succeeded, "
257
248
                "but lock is still held by someone else")
425
416
 
426
417
        peek() reads the info file of the lock holder, if any.
427
418
        """
428
 
        return self._parse_info(self.transport.get_bytes(path))
 
419
        return self._parse_info(self.transport.get(path))
429
420
 
430
421
    def peek(self):
431
422
        """Check if the lock is held by anyone.
458
449
                   )
459
450
        return s.to_string()
460
451
 
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()
 
452
    def _parse_info(self, info_file):
 
453
        return rio.read_stanza(info_file.readlines()).as_dict()
464
454
 
465
455
    def attempt_lock(self):
466
456
        """Take the lock; fail if it's already held.
534
524
                    deadline_str = time.strftime('%H:%M:%S',
535
525
                                                 time.localtime(deadline))
536
526
                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.
541
527
                self._report_function('%s %s\n'
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
 
                    )
 
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)
553
540
 
554
541
            if (max_attempts is not None) and (attempt_count >= max_attempts):
555
542
                self._trace("exceeded %d attempts")