summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2011-02-11 23:03:13 +0000
committerR. David Murray <rdmurray@bitdance.com>2011-02-11 23:03:13 +0000
commit008c0448bdcef20ed0670cae6d4b72d54a8faffa (patch)
tree74ce585360a20578080223e8696c839df0c1c533
parent46c4e4709aceaccce20b18d0e337c84d7cdac843 (diff)
downloadcpython-git-008c0448bdcef20ed0670cae6d4b72d54a8faffa.tar.gz
Merged revisions 88403 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k Test not backported since they depend on 3.x quirks. Not easy to rewrite them for 2.7. ........ r88403 | r.david.murray | 2011-02-11 17:47:17 -0500 (Fri, 11 Feb 2011) | 3 lines #11116: roll back on error during add so mailbox isn't left corrupted. ........
-rw-r--r--Lib/mailbox.py24
-rw-r--r--Misc/NEWS3
2 files changed, 21 insertions, 6 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 2b7b14e2f1..5f54ea1312 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -253,8 +253,11 @@ class Maildir(Mailbox):
tmp_file = self._create_tmp()
try:
self._dump_message(message, tmp_file)
- finally:
- _sync_close(tmp_file)
+ except BaseException:
+ tmp_file.close()
+ os.remove(tmp_file.name)
+ raise
+ _sync_close(tmp_file)
if isinstance(message, MaildirMessage):
subdir = message.get_subdir()
suffix = self.colon + message.get_info()
@@ -700,9 +703,14 @@ class _singlefileMailbox(Mailbox):
def _append_message(self, message):
"""Append message to mailbox and return (start, stop) offsets."""
self._file.seek(0, 2)
- self._pre_message_hook(self._file)
- offsets = self._install_message(message)
- self._post_message_hook(self._file)
+ before = self._file.tell()
+ try:
+ self._pre_message_hook(self._file)
+ offsets = self._install_message(message)
+ self._post_message_hook(self._file)
+ except BaseException:
+ self._file.truncate(before)
+ raise
self._file.flush()
self._file_length = self._file.tell() # Record current length of mailbox
return offsets
@@ -872,7 +880,11 @@ class MH(Mailbox):
if self._locked:
_lock_file(f)
try:
- self._dump_message(message, f)
+ try:
+ self._dump_message(message, f)
+ except BaseException:
+ os.remove(new_path)
+ raise
if isinstance(message, MHMessage):
self._dump_sequences(message, new_key)
finally:
diff --git a/Misc/NEWS b/Misc/NEWS
index 15f7f254ea..4a2ff935be 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@ Core and Builtins
Library
-------
+- Issue #11116: any error during addition of a message to a mailbox now causes
+ a rollback, instead of leaving the mailbox partially modified.
+
- Issue #8275: Fix passing of callback arguments with ctypes under Win64.
Patch by Stan Mihai.