diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-01 00:30:13 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-01 00:30:13 (GMT) |
commit | d35b8c78990bf3921648c3cb9f186f726c0f13de (patch) | |
tree | db574d17ad17116900a14ca11b49dd273c107100 /Lib/mailbox.py | |
parent | 0da5cb8db65c6f7428ba6ada7bbe97165e27b24c (diff) | |
download | cpython-d35b8c78990bf3921648c3cb9f186f726c0f13de.zip cpython-d35b8c78990bf3921648c3cb9f186f726c0f13de.tar.gz cpython-d35b8c78990bf3921648c3cb9f186f726c0f13de.tar.bz2 |
Hopefully fix the buildbot problems on test_mailbox, by computing
the maildir toc cache refresh date before actually refreshing the cache.
(see #6896)
Diffstat (limited to 'Lib/mailbox.py')
-rwxr-xr-x | Lib/mailbox.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 380f288..305b2d2 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -462,12 +462,21 @@ class Maildir(Mailbox): def _refresh(self): """Update table of contents mapping.""" - new_mtime = os.path.getmtime(os.path.join(self._path, 'new')) - cur_mtime = os.path.getmtime(os.path.join(self._path, 'cur')) + if self._last_read is not None: + for subdir in ('new', 'cur'): + mtime = os.path.getmtime(os.path.join(self._path, subdir)) + if mtime > self._last_read: + break + else: + return - if (self._last_read is not None and - new_mtime <= self._last_read and cur_mtime <= self._last_read): - 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 = {} def update_dir (subdir): @@ -482,14 +491,7 @@ class Maildir(Mailbox): update_dir('new') update_dir('cur') - # 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 = int(time.time() - 1) - self._last_read = time.time() - 1 + self._last_read = now def _lookup(self, key): """Use TOC to return subpath for given key, or raise a KeyError.""" |