FileWriter behavior between writes

This just came up during implementation discussions, so I wanted to
share it with the list.

The behavior of FileWriter in between writes isn't currently
specified.  We haven't said anything about when the underlying file is
opened or closed.  Does FileWriter.write() always do an
open-write-close, with the JS object effectively holding only a path
and offset, or could the implementation choose to keep the file open,
and have the effective offset come from the underlying file pointer?

My take: we should act as if we're always doing an open-write-close,
for maximum portability.  I believe that different operating systems
and file systems are likely to have varying behavior when there are
multiple simultaneous callers opening files at the same time.  For
example, what if script A has a FileWriter for "/foo.txt" and script B
[using the FileSystem api] moves it elsewhere?  If the file is closed,
the next write from A may act as if the file was never there.  If the
file stayed open, on some systems the write would succeed, but the
data would land at the file's new location.

Similar issues come up when files are opened for reading, then written
from another script, written from multiple scripts, etc.

Specifying that each FileWriter.write() should be indistinguishable
from an open-write-close wouldn't remove all platform-specific
behavior, but it would certainly reduce the number of problem cases.

Any thoughts?

Thanks,

      Eric Uhrhane
      ericu@google.com

Received on Thursday, 19 August 2010 01:05:57 UTC