Commit 008c0448 authored by R. David Murray's avatar R. David Murray

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.
........
parent 46c4e470
...@@ -253,7 +253,10 @@ class Maildir(Mailbox): ...@@ -253,7 +253,10 @@ class Maildir(Mailbox):
tmp_file = self._create_tmp() tmp_file = self._create_tmp()
try: try:
self._dump_message(message, tmp_file) self._dump_message(message, tmp_file)
finally: except BaseException:
tmp_file.close()
os.remove(tmp_file.name)
raise
_sync_close(tmp_file) _sync_close(tmp_file)
if isinstance(message, MaildirMessage): if isinstance(message, MaildirMessage):
subdir = message.get_subdir() subdir = message.get_subdir()
...@@ -700,9 +703,14 @@ class _singlefileMailbox(Mailbox): ...@@ -700,9 +703,14 @@ class _singlefileMailbox(Mailbox):
def _append_message(self, message): def _append_message(self, message):
"""Append message to mailbox and return (start, stop) offsets.""" """Append message to mailbox and return (start, stop) offsets."""
self._file.seek(0, 2) self._file.seek(0, 2)
before = self._file.tell()
try:
self._pre_message_hook(self._file) self._pre_message_hook(self._file)
offsets = self._install_message(message) offsets = self._install_message(message)
self._post_message_hook(self._file) self._post_message_hook(self._file)
except BaseException:
self._file.truncate(before)
raise
self._file.flush() self._file.flush()
self._file_length = self._file.tell() # Record current length of mailbox self._file_length = self._file.tell() # Record current length of mailbox
return offsets return offsets
...@@ -871,8 +879,12 @@ class MH(Mailbox): ...@@ -871,8 +879,12 @@ class MH(Mailbox):
try: try:
if self._locked: if self._locked:
_lock_file(f) _lock_file(f)
try:
try: try:
self._dump_message(message, f) self._dump_message(message, f)
except BaseException:
os.remove(new_path)
raise
if isinstance(message, MHMessage): if isinstance(message, MHMessage):
self._dump_sequences(message, new_key) self._dump_sequences(message, new_key)
finally: finally:
......
...@@ -37,6 +37,9 @@ Core and Builtins ...@@ -37,6 +37,9 @@ Core and Builtins
Library 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. - Issue #8275: Fix passing of callback arguments with ctypes under Win64.
Patch by Stan Mihai. Patch by Stan Mihai.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment