Colliding FileWriters

Hi All,

We've been looking at implementing FileWriter and had a couple of questions.

First of all, what happens if multiple pages create a FileWriter for
the same FileEntry at the same time? Will both be able to write to the
file at the same time and whoever writes lasts to a given byte wins?
This is different from how file systems normally work since as long as
file is open for writing that tends to prevent other processes from
opening the same file.

A second question is why is FileEntry.createWriter asynchronous? It
doesn't actually do any IO and so it seems like it could return an
answer synchronously.


Is the intended way for this to work that FileEntry.createWriter acts
as a choke point and ensures that only one active FileWriter for a
given FileEntry exists at the same time. I.e. if one page creates a
FileWriter for a FileEntry and starts writing to it, any other caller
to FileEntry.createWriter will wait to fire it's callback until the
first caller was done with its FileWriter. If that is the intended
design I would have expected FileWriter to have an explicit .close()
function though. Having to wait for GC to free a lock is always a bad
idea.


Would this also explain why FileEntry.getFile is asynchronous? I.e. it
won't call it's callback until all current FileWriters have been
closed?

These questions both apply to what's the intended behavior spec-wise,
as well as what does Google Chrome do in the current implementation.

/ Jonas

Received on Tuesday, 10 January 2012 21:09:46 UTC