/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/lockable_files.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-01 06:48:38 UTC
  • mfrom: (2389.1.1 0.15-to-trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20070401064838-34903c7b0d0c8007
merge 0.15 back to dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
222
222
            raise errors.BzrBadParameterNotString(a_string)
223
223
        self.put_bytes(path, a_string.encode('utf-8'))
224
224
 
225
 
    def leave_in_place(self):
226
 
        """Set this LockableFiles to not clear the physical lock on unlock."""
227
 
        self._lock.leave_in_place()
228
 
 
229
 
    def dont_leave_in_place(self):
230
 
        """Set this LockableFiles to clear the physical lock on unlock."""
231
 
        self._lock.dont_leave_in_place()
232
 
 
233
 
    def lock_write(self, token=None):
234
 
        """Lock this group of files for writing.
235
 
        
236
 
        :param token: if this is already locked, then lock_write will fail
237
 
            unless the token matches the existing lock.
238
 
        :returns: a token if this instance supports tokens, otherwise None.
239
 
        :raises TokenLockingNotSupported: when a token is given but this
240
 
            instance doesn't support using token locks.
241
 
        :raises MismatchedToken: if the specified token doesn't match the token
242
 
            of the existing lock.
243
 
 
244
 
        A token should be passed in if you know that you have locked the object
245
 
        some other way, and need to synchronise this object's state with that
246
 
        fact.
247
 
        """
 
225
    def lock_write(self):
248
226
        # mutter("lock write: %s (%s)", self, self._lock_count)
249
227
        # TODO: Upgrade locking to support using a Transport,
250
228
        # and potentially a remote locking protocol
251
229
        if self._lock_mode:
252
230
            if self._lock_mode != 'w' or not self.get_transaction().writeable():
253
231
                raise errors.ReadOnlyError(self)
254
 
            self._lock.validate_token(token)
255
232
            self._lock_count += 1
256
 
            return self._token_from_lock
257
233
        else:
258
 
            token_from_lock = self._lock.lock_write(token=token)
 
234
            self._lock.lock_write()
259
235
            #note('write locking %s', self)
260
236
            #traceback.print_stack()
261
237
            self._lock_mode = 'w'
262
238
            self._lock_count = 1
263
239
            self._set_transaction(transactions.WriteTransaction())
264
 
            self._token_from_lock = token_from_lock
265
 
            return token_from_lock
266
240
 
267
241
    def lock_read(self):
268
242
        # mutter("lock read: %s (%s)", self, self._lock_count)
359
333
    def break_lock(self):
360
334
        raise NotImplementedError(self.break_lock)
361
335
 
362
 
    def leave_in_place(self):
363
 
        raise NotImplementedError(self.leave_in_place)
364
 
 
365
 
    def dont_leave_in_place(self):
366
 
        raise NotImplementedError(self.dont_leave_in_place)
367
 
 
368
 
    def lock_write(self, token=None):
369
 
        if token is not None:
370
 
            raise errors.TokenLockingNotSupported(self)
 
336
    def lock_write(self):
371
337
        self._lock = self._transport.lock_write(self._escaped_name)
372
338
 
373
339
    def lock_read(self):
385
351
        # for old-style locks, create the file now
386
352
        self._transport.put_bytes(self._escaped_name, '',
387
353
                            mode=self._file_modebits)
388
 
 
389
 
    def validate_token(self, token):
390
 
        if token is not None:
391
 
            raise errors.TokenLockingNotSupported(self)
392