~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Martin Pool
  • Date: 2007-10-25 01:24:51 UTC
  • mto: This revision was merged to the branch mainline in revision 2946.
  • Revision ID: mbp@sourcefrog.net-20071025012451-pvqf4umf0efueoqr
unlock while in a write group now aborts the write group, unlocks, and errors.

Also, RemoteRepository.unlock() sends the unlock rpc even if there was an error
unlocking the vfs-based repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
492
492
            raise errors.UnexpectedSmartServerResponse(response)
493
493
 
494
494
    def unlock(self):
495
 
        if self._lock_count == 1 and self._lock_mode == 'w':
496
 
            # don't unlock if inside a write group.
497
 
            if self.is_in_write_group():
498
 
                raise errors.BzrError(
499
 
                    'Must end write groups before releasing write locks.')
500
495
        self._lock_count -= 1
501
 
        if not self._lock_count:
502
 
            mode = self._lock_mode
503
 
            self._lock_mode = None
 
496
        if self._lock_count > 0:
 
497
            return
 
498
        old_mode = self._lock_mode
 
499
        self._lock_mode = None
 
500
        try:
 
501
            # The real repository is responsible at present for raising an
 
502
            # exception if it's in an unfinished write group.  However, it
 
503
            # normally will *not* actually remove the lock from disk - that's
 
504
            # done by the server on receiving the Repository.unlock call.
 
505
            # This is just to let the _real_repository stay up to date.
504
506
            if self._real_repository is not None:
505
507
                self._real_repository.unlock()
506
 
            if mode != 'w':
 
508
        finally:
 
509
            # The rpc-level lock should be released even if there was a
 
510
            # problem releasing the vfs-based lock.
 
511
            if old_mode == 'w':
507
512
                # Only write-locked repositories need to make a remote method
508
513
                # call to perfom the unlock.
509
 
                return
510
 
            assert self._lock_token, 'Locked, but no token!'
511
 
            token = self._lock_token
512
 
            self._lock_token = None
513
 
            if not self._leave_lock:
514
 
                self._unlock(token)
 
514
                assert self._lock_token, \
 
515
                    '%s is locked, but has no token' \
 
516
                    % self
 
517
                old_token = self._lock_token
 
518
                self._lock_token = None
 
519
                if not self._leave_lock:
 
520
                    self._unlock(old_token)
515
521
 
516
522
    def break_lock(self):
517
523
        # should hand off to the network