Append-mode I/O on Windows and process I/O redirection
Martin Buchholz
martinrb at google.com
Sat Jun 7 21:13:59 UTC 2008
On Sat, Jun 7, 2008 at 9:12 AM, Alan Bateman <Alan.Bateman at sun.com> wrote:
> Martin Buchholz wrote:
>>
>> :
>>
>> I suppose we'll sadly have to back out all the changes for 6631352.
>> Another strategy is to open the file in FILE_WRITE_DATA mode as before,
>> but to make each individual write work in append mode.
>> Another look at the msdn documentation suggests that this is possible
>> (did I miss this when I explored the docs a year ago?)
>>
>> http://msdn.microsoft.com/en-us/library/aa365747(VS.85).aspx
>>
>> Use WriteFile with a non-null OVERLAPPED, with Offset = OffsetHigh =
>> 0xffffffff
>>
>> "To write to the end of file, specify both the Offset and OffsetHigh
>> members of the OVERLAPPED structure as 0xFFFFFFFF. This is
>> functionally equivalent to previously calling the CreateFile function
>> to open hFile using FILE_APPEND_DATA access."
>>
>> The above has a good chance of properly fixing 6631352.
>>
>
> I agree this is the approach to try. I've used WriteFile for append mode
> using this approach in another context and it worked although I don't recall
> ever checking its atomicity. The MSDN documentation is never clear on such
> topics but the AtomicAppend test that you included with these changes can
> quickly check.
OK. I'm not currently volunteering to implement this,
but I'm willing to be a reviewer.
>> What should the process code do, given that it doesn't control
>> how the subprocess will perform individual writes?
>>
>
> Maybe ProcessBuilder can open the file itself in append mode rather than
> using FileOutputStream.
When I first implemented this, keeping track of append mode throughout
various software layers was a burden. I guess the output streams
and channels will have to know whether they are in append mode or not.
Perhaps it is easiest to implement append mode by using the current
code that uses FileOutputStream and extracts the HANDLE from that,
but at the last moment replacing the HANDLE with a new HANDLE
that has FILE_WRITE_DATA turned off before calling CreateProcess.
Martin
> -Alan.
>
More information about the core-libs-dev
mailing list