]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix Maildir initialization so that maildir contents are read correctly.
authorPetri Lehtinen <petri@digip.org>
Sat, 5 Nov 2011 07:44:59 +0000 (09:44 +0200)
committerPetri Lehtinen <petri@digip.org>
Sat, 5 Nov 2011 07:44:59 +0000 (09:44 +0200)
Closes #13254.

Lib/mailbox.py
Lib/test/test_mailbox.py
Misc/NEWS

index e23ea8c6329c6a54e460c43b458694c761dedc8c..a6777293861bc0828d09a1d7ad92df1f99305be0 100644 (file)
@@ -273,11 +273,9 @@ class Maildir(Mailbox):
             else:
                 raise NoSuchMailboxError(self._path)
         self._toc = {}
-        self._toc_mtimes = {}
-        for subdir in ('cur', 'new'):
-            self._toc_mtimes[subdir] = os.path.getmtime(self._paths[subdir])
-        self._last_read = time.time()  # Records last time we read cur/new
-        self._skewfactor = 0.1         # Adjust if os/fs clocks are skewing
+        self._toc_mtimes = {'cur': 0, 'new': 0}
+        self._last_read = 0         # Records last time we read cur/new
+        self._skewfactor = 0.1      # Adjust if os/fs clocks are skewing
 
     def add(self, message):
         """Add message and return assigned key."""
index fb4812dd9947359ceae6134e7e5d57e2a3148af7..e0d8da29fea77de98a609ea58eae902c18ddff0a 100644 (file)
@@ -801,6 +801,25 @@ class TestMaildir(TestMailbox):
                                           key1: os.path.join('new', key1),
                                           key2: os.path.join('new', key2)})
 
+    def test_refresh_after_safety_period(self):
+        # Issue #13254: Call _refresh after the "file system safety
+        # period" of 2 seconds has passed; _toc should still be
+        # updated because this is the first call to _refresh.
+        key0 = self._box.add(self._template % 0)
+        key1 = self._box.add(self._template % 1)
+
+        self._box = self._factory(self._path)
+        self.assertEqual(self._box._toc, {})
+
+        # Emulate sleeping. Instead of sleeping for 2 seconds, use the
+        # skew factor to make _refresh think that the filesystem
+        # safety period has passed and re-reading the _toc is only
+        # required if mtimes differ.
+        self._box._skewfactor = -2
+
+        self._box._refresh()
+        self.assertEqual(sorted(self._box._toc.keys()), sorted([key0, key1]))
+
     def test_lookup(self):
         # Look up message subpaths in the TOC
         self.assertRaises(KeyError, lambda: self._box._lookup('foo'))
@@ -876,6 +895,8 @@ class TestMaildir(TestMailbox):
         self.assertFalse((perms & 0o111)) # Execute bits should all be off.
 
     def test_reread(self):
+        # Do an initial unconditional refresh
+        self._box._refresh()
 
         # Put the last modified times more than two seconds into the past
         # (because mtime may have a two second granularity)
index e8917ed3bc498193c973bb2c0a938acb11d23ef0..22400c68ede869a5d9804cbd57acc7c6fac95427 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -70,6 +70,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #13254: Fix Maildir initialization so that maildir contents
+  are read correctly.
+
 - Issue #3067: locale.setlocale() now raises TypeError if the second
   argument is an invalid iterable. Initial patch by Jyrki Pulliainen.