bitcoin/bitcoin — pull request #2042 by luke-jr (2012-11-26 21:48:52+00:00)
Title: Fix OpenDiskFile's fReadOnly flag to work, as well as (non-trivial) data-loss race

OpenDiskFile was always opening files in "rb+" mode (read-write binary), and if that failed and fReadOnly was false, trying to truncate the file. Truncate would always fail (AFAIK) unless a race condition set the file read-write between the two attempts.

This changes it to actually honour fReadOnly, and never try to truncate the file.
If we want to try truncating in !fReadOnly mode, I'm pretty sure we need to unlink first.

This bug was introduced as part of ultraprune, so does not affect any released versions.