Hopefully fix the buildbot problems on test_mailbox, by computing

the maildir toc cache refresh date before actually refreshing the cache.

(see #6896)
This commit is contained in:
Antoine Pitrou 2009-11-01 00:30:13 +00:00
parent 0da5cb8db6
commit d35b8c7899
1 changed files with 15 additions and 13 deletions

View File

@ -462,13 +462,22 @@ class Maildir(Mailbox):
def _refresh(self): def _refresh(self):
"""Update table of contents mapping.""" """Update table of contents mapping."""
new_mtime = os.path.getmtime(os.path.join(self._path, 'new')) if self._last_read is not None:
cur_mtime = os.path.getmtime(os.path.join(self._path, 'cur')) for subdir in ('new', 'cur'):
mtime = os.path.getmtime(os.path.join(self._path, subdir))
if (self._last_read is not None and if mtime > self._last_read:
new_mtime <= self._last_read and cur_mtime <= self._last_read): break
else:
return return
# We record the current time - 1sec so that, if _refresh() is called
# again in the same second, we will always re-read the mailbox
# just in case it's been modified. (os.path.mtime() only has
# 1sec resolution.) This results in a few unnecessary re-reads
# when _refresh() is called multiple times in the same second,
# but once the clock ticks over, we will only re-read as needed.
now = time.time() - 1
self._toc = {} self._toc = {}
def update_dir (subdir): def update_dir (subdir):
path = os.path.join(self._path, subdir) path = os.path.join(self._path, subdir)
@ -482,14 +491,7 @@ class Maildir(Mailbox):
update_dir('new') update_dir('new')
update_dir('cur') update_dir('cur')
# We record the current time - 1sec so that, if _refresh() is called self._last_read = now
# again in the same second, we will always re-read the mailbox
# just in case it's been modified. (os.path.mtime() only has
# 1sec resolution.) This results in a few unnecessary re-reads
# when _refresh() is called multiple times in the same second,
# but once the clock ticks over, we will only re-read as needed.
now = int(time.time() - 1)
self._last_read = time.time() - 1
def _lookup(self, key): def _lookup(self, key):
"""Use TOC to return subpath for given key, or raise a KeyError.""" """Use TOC to return subpath for given key, or raise a KeyError."""