~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 22:30:22 UTC
  • mto: This revision was merged to the branch mainline in revision 1569.
  • Revision ID: mbp@sourcefrog.net-20060221223022-0d73c36b63fc9bcf
New LockDir.force_break and simple test case

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
        self.transport.delete(tmpname + self.INFO_NAME)
204
204
        self.transport.rmdir(tmpname)
205
205
 
 
206
    def force_break(self):
 
207
        """Release a lock held by another process.
 
208
 
 
209
        WARNING: This should only be used when the other process is dead; if
 
210
        it still thinks it has the lock there will be two concurrent writers.
 
211
        In general the user's approval should be sought for lock breaks.
 
212
 
 
213
        After the lock is broken it will not be held by any process.
 
214
        It is possible that another process may sneak in and take the 
 
215
        lock before the breaking process acquires it.
 
216
        """
 
217
        if self._lock_held:
 
218
            raise AssertionError("can't break own lock: %r" % self)
 
219
        tmpname = '%s.broken.%s.tmp' % (self.path, rand_chars(20))
 
220
        self.transport.rename(self.path, tmpname)
 
221
        self.transport.delete(tmpname + self.INFO_NAME)
 
222
        self.transport.rmdir(tmpname)
 
223
 
206
224
    def confirm(self):
207
225
        """Make sure that the lock is still held by this locker.
208
226
 
292
310
                time.sleep(poll)
293
311
            else:
294
312
                raise LockContention(self)
 
313