1692
1692
if (self._header_state == DirState.IN_MEMORY_MODIFIED or
1693
1693
self._dirblock_state == DirState.IN_MEMORY_MODIFIED):
1695
if self._lock_state == 'w':
1696
out_file = self._state_file
1699
# Try to grab a write lock so that we can update the file.
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
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
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
1710
if e.errno in (errno.ENOENT, errno.EPERM, errno.EACCES,
1712
# Ignore these errors and just don't save anything
1718
out_file.writelines(self.get_lines())
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
1724
if wlock is not None:
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.
1727
1722
def _set_data(self, parent_ids, dirblocks):
1728
1723
"""Set the full dirstate data in memory.