~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Martin Pool
  • Date: 2006-02-21 07:03:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1569.
  • Revision ID: mbp@sourcefrog.net-20060221070359-e334fefdbbc1a45b
LockDir should use Transport.rename when releasing locks too.

Add simple example of usage as a doctest.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
object per actual lock on disk.  This module does nothing to prevent aliasing
78
78
and deadlocks will likely occur if the locks are aliased.
79
79
 
80
 
 
81
 
 
82
80
In the future we may add a "freshen" method which can be called
83
81
by a lock holder to check that their lock has not been broken, and to 
84
82
update the timestamp within it.
85
83
 
 
84
Example usage:
 
85
 
 
86
>>> from bzrlib.transport.memory import MemoryTransport
 
87
>>> # typically will be obtained from a BzrDir, Branch, etc
 
88
>>> t = MemoryTransport()
 
89
>>> l = LockDir(t, 'sample-lock')
 
90
>>> l.wait_lock()
 
91
>>> # do something here
 
92
>>> l.unlock()
 
93
 
86
94
"""
87
95
 
88
96
import os
188
196
        # rename before deleting, because we can't atomically remove the whole
189
197
        # tree
190
198
        tmpname = '%s.releasing.%s.tmp' % (self.path, rand_chars(20))
191
 
        self.transport.move(self.path, tmpname)
 
199
        self.transport.rename(self.path, tmpname)
192
200
        self._lock_held = False
193
201
        self.transport.delete(tmpname + self.INFO_NAME)
194
202
        self.transport.rmdir(tmpname)