~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/repository.py

Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
smart protocol as appropriate, so that locking operations on RemoteRepositories
work correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
            return SmartServerResponse(('yes', ))
141
141
        else:
142
142
            return SmartServerResponse(('no', ))
 
143
 
 
144
 
 
145
class SmartServerRepositoryLockWrite(SmartServerRepositoryRequest):
 
146
 
 
147
    def do_repository_request(self, repository, token):
 
148
        # XXX: this probably should not have a token.
 
149
        if token == '':
 
150
            token = None
 
151
        try:
 
152
            token = repository.lock_write(token=token)
 
153
        except errors.LockContention, e:
 
154
            return SmartServerResponse(('LockContention',))
 
155
        repository.leave_lock_in_place()
 
156
        repository.unlock()
 
157
        if token is None:
 
158
            token = ''
 
159
        return SmartServerResponse(('ok', token))
 
160
 
 
161
 
 
162
class SmartServerRepositoryUnlock(SmartServerRepositoryRequest):
 
163
 
 
164
    def do_repository_request(self, repository, token):
 
165
        try:
 
166
            repository.lock_write(token=token)
 
167
        except errors.TokenMismatch, e:
 
168
            return SmartServerResponse(('TokenMismatch',))
 
169
        repository.dont_leave_lock_in_place()
 
170
        repository.unlock()
 
171
        return SmartServerResponse(('ok',))
 
172