~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-23 17:51:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5390.
  • Revision ID: john@arbash-meinel.com-20100823175117-hr3b7p8gkw4ap8bb
Change the _test names to _get and _py so that it doesn't provoke bad smells :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
        LockBreakMismatch,
121
121
        LockBroken,
122
122
        LockContention,
123
 
        LockCorrupt,
124
123
        LockFailed,
125
124
        LockNotHeld,
126
125
        NoSuchFile,
349
348
        it possibly being still active.
350
349
        """
351
350
        self._check_not_locked()
352
 
        try:
353
 
            holder_info = self.peek()
354
 
        except LockCorrupt, e:
355
 
            # The lock info is corrupt.
356
 
            if bzrlib.ui.ui_factory.get_boolean("Break (corrupt %r)" % (self,)):
357
 
                self.force_break_corrupt(e.file_data)
358
 
            return
 
351
        holder_info = self.peek()
359
352
        if holder_info is not None:
360
353
            lock_info = '\n'.join(self._format_lock_info(holder_info))
361
 
            if bzrlib.ui.ui_factory.confirm_action(
362
 
                "Break %(lock_info)s", 'bzrlib.lockdir.break', 
363
 
                dict(lock_info=lock_info)):
 
354
            if bzrlib.ui.ui_factory.get_boolean("Break %s" % lock_info):
364
355
                self.force_break(holder_info)
365
356
 
366
357
    def force_break(self, dead_holder_info):
404
395
        for hook in self.hooks['lock_broken']:
405
396
            hook(result)
406
397
 
407
 
    def force_break_corrupt(self, corrupt_info_lines):
408
 
        """Release a lock that has been corrupted.
409
 
        
410
 
        This is very similar to force_break, it except it doesn't assume that
411
 
        self.peek() can work.
412
 
        
413
 
        :param corrupt_info_lines: the lines of the corrupted info file, used
414
 
            to check that the lock hasn't changed between reading the (corrupt)
415
 
            info file and calling force_break_corrupt.
416
 
        """
417
 
        # XXX: this copes with unparseable info files, but what about missing
418
 
        # info files?  Or missing lock dirs?
419
 
        self._check_not_locked()
420
 
        tmpname = '%s/broken.%s.tmp' % (self.path, rand_chars(20))
421
 
        self.transport.rename(self._held_dir, tmpname)
422
 
        # check that we actually broke the right lock, not someone else;
423
 
        # there's a small race window between checking it and doing the
424
 
        # rename.
425
 
        broken_info_path = tmpname + self.__INFO_NAME
426
 
        f = self.transport.get(broken_info_path)
427
 
        broken_lines = f.readlines()
428
 
        if broken_lines != corrupt_info_lines:
429
 
            raise LockBreakMismatch(self, broken_lines, corrupt_info_lines)
430
 
        self.transport.delete(broken_info_path)
431
 
        self.transport.rmdir(tmpname)
432
 
        result = lock.LockResult(self.transport.abspath(self.path))
433
 
        for hook in self.hooks['lock_broken']:
434
 
            hook(result)
435
 
 
436
398
    def _check_not_locked(self):
437
399
        """If the lock is held by this instance, raise an error."""
438
400
        if self._lock_held:
497
459
        return s.to_string()
498
460
 
499
461
    def _parse_info(self, info_bytes):
500
 
        lines = osutils.split_lines(info_bytes)
501
 
        try:
502
 
            stanza = rio.read_stanza(lines)
503
 
        except ValueError, e:
504
 
            mutter('Corrupt lock info file: %r', lines)
505
 
            raise LockCorrupt("could not parse lock info file: " + str(e),
506
 
                              lines)
 
462
        stanza = rio.read_stanza(osutils.split_lines(info_bytes))
507
463
        if stanza is None:
508
464
            # see bug 185013; we fairly often end up with the info file being
509
465
            # empty after an interruption; we could log a message here but