~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/dirstate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-20 22:39:38 UTC
  • mfrom: (2363.3.4 simple_locking)
  • Revision ID: pqm@pqm.ubuntu.com-20070320223938-97fdc295a1111e36
(John Arbash Meinel) allow win32 to grab a write lock after 'bzr status', so that we can record the updated stat values.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1692
1692
        if (self._header_state == DirState.IN_MEMORY_MODIFIED or
1693
1693
            self._dirblock_state == DirState.IN_MEMORY_MODIFIED):
1694
1694
 
1695
 
            if self._lock_state == 'w':
1696
 
                out_file = self._state_file
1697
 
                wlock = None
1698
 
            else:
1699
 
                # Try to grab a write lock so that we can update the file.
1700
 
                try:
1701
 
                    wlock = lock.WriteLock(self._filename)
1702
 
                except (errors.LockError, errors.LockContention), e:
1703
 
                    # We couldn't grab the lock, so just leave things dirty in
1704
 
                    # memory.
 
1695
            grabbed_write_lock = False
 
1696
            if self._lock_state != 'w':
 
1697
                grabbed_write_lock, new_lock = self._lock_token.temporary_write_lock()
 
1698
                # Switch over to the new lock, as the old one may be closed.
 
1699
                # TODO: jam 20070315 We should validate the disk file has
 
1700
                #       not changed contents. Since temporary_write_lock may
 
1701
                #       not be an atomic operation.
 
1702
                self._lock_token = new_lock
 
1703
                self._state_file = new_lock.f
 
1704
                if not grabbed_write_lock:
 
1705
                    # We couldn't grab a write lock, so we switch back to a read one
1705
1706
                    return
1706
 
                except IOError, e:
1707
 
                    # This may be a read-only tree, or someone else may have a
1708
 
                    # ReadLock. so handle the case when we cannot grab a write
1709
 
                    # lock
1710
 
                    if e.errno in (errno.ENOENT, errno.EPERM, errno.EACCES,
1711
 
                                   errno.EAGAIN):
1712
 
                        # Ignore these errors and just don't save anything
1713
 
                        return
1714
 
                    raise
1715
 
                out_file = wlock.f
1716
1707
            try:
1717
 
                out_file.seek(0)
1718
 
                out_file.writelines(self.get_lines())
1719
 
                out_file.truncate()
1720
 
                out_file.flush()
 
1708
                self._state_file.seek(0)
 
1709
                self._state_file.writelines(self.get_lines())
 
1710
                self._state_file.truncate()
 
1711
                self._state_file.flush()
1721
1712
                self._header_state = DirState.IN_MEMORY_UNMODIFIED
1722
1713
                self._dirblock_state = DirState.IN_MEMORY_UNMODIFIED
1723
1714
            finally:
1724
 
                if wlock is not None:
1725
 
                    wlock.unlock()
 
1715
                if grabbed_write_lock:
 
1716
                    self._lock_token = self._lock_token.restore_read_lock()
 
1717
                    self._state_file = self._lock_token.f
 
1718
                    # TODO: jam 20070315 We should validate the disk file has
 
1719
                    #       not changed contents. Since restore_read_lock may
 
1720
                    #       not be an atomic operation.
1726
1721
 
1727
1722
    def _set_data(self, parent_ids, dirblocks):
1728
1723
        """Set the full dirstate data in memory.