[Python-Dev] cpython (2.7): #9559: Append data to single-file mailbox files if messages are only added

R. David Murray rdmurray at bitdance.com
Thu Jun 28 17:08:43 CEST 2012


On Thu, 28 Jun 2012 16:16:45 +0300, Petri Lehtinen <petri at digip.org> wrote:
> Antoine Pitrou wrote:
> > > If messages were only added, a new file is no longer created and
> > > renamed over the old file when flush() is called on an mbox, MMDF or
> > > Babyl mailbox.
> > 
> > Why so? Appending is not atomic and, if it fails in the middle, you
> > could get a corrupt mbox file.
> > Furthermore, I disagree that it's a bugfix: IMO it should wait for 3.4.
> 
> The code previosly already appended messages to the end of the file
> when calling add(). This patch just changed it to not do a full
> rewrite when flush() is called. Having a partially written message in
> the end of your mailbox doesn't seem like a fatal corruption to me.
> 
> Furthermore, I (and R. David Murray) think this is not so surprising
> for users. Most (or all) other implementations always write changes
> in-place without renaming, as this makes it possible to find out
> whether new mail has arrived.

It is true, however, that Petri found that mutt (I think?) does some extra
gymnastics to provide recovery where the write fails part way through,
and it would be worth adding that as an enhanced bugfix if someone
has the motivation (basically, make a copy of the unmodified mailbox
and mv it back into place if the write fails).

Even that fix won't prevent corruption in the case of a system crash,
but, then, not much will in that case.

--David


More information about the Python-Dev mailing list