]> granicus.if.org Git - python/commitdiff
#7627: MH.remove() would fail if the MH mailbox was locked;
authorAndrew M. Kuchling <amk@amk.ca>
Mon, 22 Feb 2010 18:42:07 +0000 (18:42 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Mon, 22 Feb 2010 18:42:07 +0000 (18:42 +0000)
it would call _unlock_file() and pass it a closed file object.  Noted by Rob Austein.

Lib/mailbox.py
Lib/test/test_mailbox.py

index 4da556935ecea647748cde7a597cfd24e2f1b61e..2b7b14e2f1aab8620a13c2a88d42bfb18e32c13f 100755 (executable)
@@ -892,17 +892,9 @@ class MH(Mailbox):
                 raise KeyError('No message with key: %s' % key)
             else:
                 raise
-        try:
-            if self._locked:
-                _lock_file(f)
-            try:
-                f.close()
-                os.remove(os.path.join(self._path, str(key)))
-            finally:
-                if self._locked:
-                    _unlock_file(f)
-        finally:
+        else:
             f.close()
+            os.remove(path)
 
     def __setitem__(self, key, message):
         """Replace the keyed message; raise KeyError if it doesn't exist."""
index c88af0613722cc4ae5a2667d59e250e0be748168..7575ca7e65e62b474308458371a780a6d4ebad1a 100644 (file)
@@ -979,6 +979,13 @@ class TestMH(TestMailbox):
         key0 = self._box.add(msg0)
         refmsg0 = self._box.get_message(key0)
 
+    def test_issue7627(self):
+        msg0 = mailbox.MHMessage(self._template % 0)
+        key0 = self._box.add(msg0)
+        self._box.lock()
+        self._box.remove(key0)
+        self._box.unlock()
+
     def test_pack(self):
         # Pack the contents of the mailbox
         msg0 = mailbox.MHMessage(self._template % 0)