In message <
a965705...@nails.abbeypress.net>
on 23 May 2013 Jim Nagel wrote:
> Is there any way of detecting that somebody else on the network
> already has a file open? It would be sensible if anybody then trying
> to open the same file or document would get a read-only copy (ideally
> with a message saying so).
Martin's response started off on the track of examining whether a file was
open in the sense of it having a current file handle, rather than whether the
content of the file appears in an editor. As Ron rightly pointed out, most
editors open the file (in the file handle sense) briefly to load the data,
and then close it, allowing other applications in the meantime to read and
write the same file. That is the problem you want addressed.
Before I turn to that, I just want to digress onto file handles, and files
being "open" in that sense, as I think it might help to get that clear. One
fundamental issue is that different filing systems have different
capabilities, and in a networked situation you might be up against any of
them.
If we talk purely about Acorn filing systems, a file can be open read-only
several times over by different applications (or indeed, multiple times by
the same application) but if it is open for read-write access then it is
impossible for it to be open read-only at the same time, and if a file is
open read-only once or more, it cannot be opened read-write.
Typically on Unix systems, however, a file can be open once read-write and
multiple times read-only simultaneously. Therefore, if your network file
system is NFS-based, it might be possible for one application to have the
file open read-write and others to then access read-only. But it depends on
the filing system's underlying rules. It's a long time since I write a RISC
OS filing system, but I don't think FileSwitch makes any assumptions as to
how the actual filing systems it talks to behave, so both behaviours are
potentially valid under RISC OS. But in my experience most developers have
chosen to make their filing systems behave like FileCore in the way that I
have just described.
What I have discussed so far is purely on the level of the file system, but
we really need to consider it on the level of the application. If you have a
document open for editing in a window, it is up to the author of the
application as to whether that document is kept open as a file during that
process. As Ron says, most do not. There are a few exceptions.
For example, !PDF keeps the file open read-only all the while, which has the
effect that you cannot rename or move a PDF if it is open in !PDF. This must
be because !PDF does not load the whole file into memory at once, and is
therefore going to need to access it again, but it could have been
implemented differently, with !PDF reopening the file whenever it needs to,
and putting up appropriate error messages if the file has been moved or
updated in the mean time.
To be honest, closing the file would be a better way to proceed: in theory
the application developer should be dealing with the file moving or changing
anyway, as (a) the file might be on a filing system which allows this to
happen, and (b) the filehandle could be closed accidentally or on purpose by
another application. So keeping a file open, in the file handle sense, is no
guarantee against Bad Things happening.
Another exception is EasiWriter, where it has the option of loading just
portions of a very large document and reading the rest as required, but it
does not keep the file open with a file handle: it reopens it as required.
So your suggestion has to be implemented at the application level, by each
application author. Some applications are already better at handling the
kind of conflicts you can get than others. If I open a text file in two
different text editors, make changes and save from one and then make changes
and save from the other, some text editors will just save and overwrite the
other edits I made. Others will spot that the date of the file about to be
overwritten is more recent than when the file was loaded, and will warn the
user. Does Impression offer this safeguard? Try experimenting, and if it
does not, that would be a sensible enhancement request. A really
sophisticated editor which spots this situation might then be able to offer
to merge the changes, if it knew what changes you had made since loading the
file.
The way this works with Microsoft Word, and the like, is that a temporary,
hidden file is placed in the same directory as the open Word document, and
other copies of Word running on other machines will examine this to see if
the file is being edited already, and who has opened it. You are then
offered the chance to open it read-only.
But all these options are application-level solutions. If Zap, say, adopted
the same arrangement to record that someone was in the process of editing a
file, then StrongEd running on another machine would only be able to detect
that the file was open in Zap if it was aware of that mechanism. OK, for
Impression that might not be such an issue, but Impression files can be
loaded by Ovation Pro, so it's not as safe as you might think!
(The other issue here is that the native RISC OS filing systems do not
have hidden files, and in addition, users are much more aware of the contents
of directories than they are on Windows, so it could get quite alarming
seeing extra files appear whenever anything is open for editing.)
So it is all rather fraught with difficulty, I fear!
--
Matthew Phillips
Durham