]> granicus.if.org Git - python/commitdiff
This should finally fix #6896. Let's watch the buildbots.
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 1 Nov 2009 21:29:33 +0000 (21:29 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 1 Nov 2009 21:29:33 +0000 (21:29 +0000)
Lib/mailbox.py
Lib/test/test_mailbox.py

index 305b2d2449241c4229c712e59238fa84699a3ee7..74359b7aa6325fd6bcf7f492352efe64a5b11fb1 100755 (executable)
@@ -238,6 +238,9 @@ class Maildir(Mailbox):
                 raise NoSuchMailboxError(self._path)
         self._toc = {}
         self._last_read = None          # Records last time we read cur/new
+        # NOTE: we manually invalidate _last_read each time we do any
+        # modifications ourselves, otherwise we might get tripped up by
+        # bogus mtime behaviour on some systems (see issue #6896).
 
     def add(self, message):
         """Add message and return assigned key."""
@@ -271,11 +274,15 @@ class Maildir(Mailbox):
                 raise
         if isinstance(message, MaildirMessage):
             os.utime(dest, (os.path.getatime(dest), message.get_date()))
+        # Invalidate cached toc
+        self._last_read = None
         return uniq
 
     def remove(self, key):
         """Remove the keyed message; raise KeyError if it doesn't exist."""
         os.remove(os.path.join(self._path, self._lookup(key)))
+        # Invalidate cached toc (only on success)
+        self._last_read = None
 
     def discard(self, key):
         """If the keyed message exists, remove it."""
@@ -310,6 +317,8 @@ class Maildir(Mailbox):
         if isinstance(message, MaildirMessage):
             os.utime(new_path, (os.path.getatime(new_path),
                                 message.get_date()))
+        # Invalidate cached toc
+        self._last_read = None
 
     def get_message(self, key):
         """Return a Message representation or raise a KeyError."""
@@ -364,7 +373,9 @@ class Maildir(Mailbox):
 
     def flush(self):
         """Write any pending changes to disk."""
-        return  # Maildir changes are always written immediately.
+        # Maildir changes are always written immediately, so there's nothing
+        # to do except invalidate our cached toc.
+        self._last_read = None
 
     def lock(self):
         """Lock the mailbox."""
index 2abb354af2ac6a725a476497680c5275e1a57a73..548850ad1ea32e3d4b4c83b590c1986bfd446029 100644 (file)
@@ -684,6 +684,9 @@ class TestMaildir(TestMailbox):
         self.assertEqual(self._box._lookup(key0), os.path.join('new', key0))
         os.remove(os.path.join(self._path, 'new', key0))
         self.assertEqual(self._box._toc, {key0: os.path.join('new', key0)})
+        # Be sure that the TOC is read back from disk (see issue #6896
+        # about bad mtime behaviour on some systems).
+        self._box.flush()
         self.assertRaises(KeyError, lambda: self._box._lookup(key0))
         self.assertEqual(self._box._toc, {})