~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Martin Pool
  • Date: 2010-02-27 01:34:49 UTC
  • mto: This revision was merged to the branch mainline in revision 5064.
  • Revision ID: mbp@canonical.com-20100227013449-zxostilwfoendxfv
Handle "Directory not empty" from ftp as DirectoryNotEmpty.

FtpTransport._translate_ftp_error can handle all ftp errors; there's no clear
distinction between 'temporary' and 'permament'.

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
 
116
from bzrlib.decorators import only_raises
115
117
from bzrlib.errors import (
116
118
        DirectoryNotEmpty,
117
119
        FileExists,
240
242
        # incorrect.  It's possible some other servers or filesystems will
241
243
        # have a similar bug allowing someone to think they got the lock
242
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.
243
250
        info = self.peek()
244
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!")
245
255
        if info['nonce'] != self.nonce:
246
256
            self._trace("rename succeeded, "
247
257
                "but lock is still held by someone else")
286
296
                                            info_bytes)
287
297
        return tmpname
288
298
 
 
299
    @only_raises(LockNotHeld, LockBroken)
289
300
    def unlock(self):
290
301
        """Release a held lock
291
302
        """
293
304
            self._fake_read_lock = False
294
305
            return
295
306
        if not self._lock_held:
296
 
            raise LockNotHeld(self)
 
307
            return lock.cant_unlock_not_held(self)
297
308
        if self._locked_via_token:
298
309
            self._locked_via_token = False
299
310
            self._lock_held = False
414
425
 
415
426
        peek() reads the info file of the lock holder, if any.
416
427
        """
417
 
        return self._parse_info(self.transport.get(path))
 
428
        return self._parse_info(self.transport.get_bytes(path))
418
429
 
419
430
    def peek(self):
420
431
        """Check if the lock is held by anyone.
447
458
                   )
448
459
        return s.to_string()
449
460
 
450
 
    def _parse_info(self, info_file):
451
 
        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()
452
464
 
453
465
    def attempt_lock(self):
454
466
        """Take the lock; fail if it's already held.
522
534
                    deadline_str = time.strftime('%H:%M:%S',
523
535
                                                 time.localtime(deadline))
524
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.
525
541
                self._report_function('%s %s\n'
526
 
                                      '%s\n' # held by
527
 
                                      '%s\n' # locked ... ago
528
 
                                      'Will continue to try until %s, unless '
529
 
                                      'you press Ctrl-C\n'
530
 
                                      'If you\'re sure that it\'s not being '
531
 
                                      'modified, use bzr break-lock %s',
532
 
                                      start,
533
 
                                      formatted_info[0],
534
 
                                      formatted_info[1],
535
 
                                      formatted_info[2],
536
 
                                      deadline_str,
537
 
                                      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
                    )
538
553
 
539
554
            if (max_attempts is not None) and (attempt_count >= max_attempts):
540
555
                self._trace("exceeded %d attempts")