~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Robert Collins
  • Date: 2006-05-05 04:43:35 UTC
  • mfrom: (1687.1.17 break-lock)
  • mto: This revision was merged to the branch mainline in revision 1701.
  • Revision ID: robertc@robertcollins.net-20060505044335-0e785bae0df1047e
Merge break-lock command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
218
218
        # rename before deleting, because we can't atomically remove the whole
219
219
        # tree
220
220
        tmpname = '%s/releasing.%s.tmp' % (self.path, rand_chars(20))
 
221
        # gotta own it to unlock
 
222
        self.confirm()
221
223
        self.transport.rename(self._held_dir, tmpname)
222
224
        self._lock_held = False
223
225
        self.transport.delete(tmpname + self.__INFO_NAME)
224
226
        self.transport.rmdir(tmpname)
225
227
 
 
228
    def break_lock(self):
 
229
        """Break a lock not held by this instance of LockDir.
 
230
 
 
231
        This is a UI centric function: it uses the bzrlib.ui.ui_factory to
 
232
        prompt for input if a lock is detected and there is any doubt about
 
233
        it possibly being still active.
 
234
        """
 
235
        self._check_not_locked()
 
236
        holder_info = self.peek()
 
237
        if holder_info is not None:
 
238
            if bzrlib.ui.ui_factory.get_boolean(
 
239
                "Break lock %s held by %s@%s [process #%s]" % (
 
240
                    self.transport,
 
241
                    holder_info["user"],
 
242
                    holder_info["hostname"],
 
243
                    holder_info["pid"])):
 
244
                self.force_break(holder_info)
 
245
        
226
246
    def force_break(self, dead_holder_info):
227
247
        """Release a lock held by another process.
228
248
 
241
261
        """
242
262
        if not isinstance(dead_holder_info, dict):
243
263
            raise ValueError("dead_holder_info: %r" % dead_holder_info)
244
 
        if self._lock_held:
245
 
            raise AssertionError("can't break own lock: %r" % self)
 
264
        self._check_not_locked()
246
265
        current_info = self.peek()
247
266
        if current_info is None:
248
267
            # must have been recently released
261
280
        self.transport.delete(broken_info_path)
262
281
        self.transport.rmdir(tmpname)
263
282
 
 
283
    def _check_not_locked(self):
 
284
        """If the lock is held by this instance, raise an error."""
 
285
        if self._lock_held:
 
286
            raise AssertionError("can't break own lock: %r" % self)
 
287
 
264
288
    def confirm(self):
265
289
        """Make sure that the lock is still held by this locker.
266
290