Re: Exclusive File Access
Re: Exclusive File Access
- Subject: Re: Exclusive File Access
- From: mw <email@hidden>
- Date: Thu, 21 Nov 2002 06:28:16 -0500
>
> Here's the problem with my app, that my customers can run into.
>
> Person A
>
> opens file (which reads it all into RAM), Person B opens file (ditto),
>
> Person A makes changes and saves it, Person B makes changes and saves
>
> it.
>
> Person A's changes are thrown away, there is no warning that anything
>
> is
>
> wrong. This is bad.
Okay, how about I answer your question instead of listing all of the reasons
why it is a bad idea (which I disagree with).
Here's my idea. Let's say that Person A opens a file (that is all well and
simple, right?), and Person B opens the same file at about the same time
(doesn't really matter). Person A makes some changes. The program checks
either the modification date of the file, or some other "change-tracker"
(such as an MD5 hash, which I believe was suggested previously). It sees
that the file hasn't changed, so it does a normal save (overwriting the
original file with the new information). Now, let's say that Person B makes
some changes to a completely different part of the file. When he saves, the
program performs the same check, and finds that there have been
modifications to the file between the time it was opened by Person B and the
current save. So The program reads the whole file into memory. Now, we have
2 copies of the file in RAM, the original one (modified by Person A,
though), and the one modified by Person B. So the program starts the process
of comparing the elements of 2 file contents in RAM, and then writes the
verified changes back to file. For example, the first 3 objects are the same
in both files, so they are written to the hard disk. However, the next 3
objects are different in the original file, so those changes are written
back to the file. The next 3 objects are different in Person B's file, so
those are written back. See the pattern?
There would obviously to be lots of error checking (for example, checking to
see which element is newer when comparing for the save, Person A's or Person
B's, etc.) in your code, but I just ran off that idea from the top of my
head. I think it is quite a good start though :-).
Can anybody verify my logic for fundamental flaws here? If it works okay, I
think it is quite a good method for creating, for example, Network-savvy
applications that allow multiple users on a LAN to edit the same file
without having to worry about losing any of their changes (other than
another user altering the changes they made, which can happen in even
single-access files quite easily).
-- mw
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.