Re: mcedit file locking
- From: Adam Byrtek / alpha <alpha student uci agh edu pl>
- To: Pavel Roskin <proski gnu org>
- Cc: Pavel Tsekov <ptsekov gmx net>, mc-devel gnome org
- Subject: Re: mcedit file locking
- Date: Sun, 30 Mar 2003 21:23:16 +0200
On Wed, Mar 26, 2003 at 05:01:31PM -0500, Pavel Roskin wrote:
> OK, it seems that write lock using fcntl for the period when the file is
> being edited would be the best solution.
Tried to do this today, but looks like it would be quite hard to
achieve. It's because mc opens and closes the file multiple times
during edit (twice in fast-load mode, more often in buffer mode), and
lockf (fcntl lock) is destroyed on every close (even if more
desciptors on this file are open).
I've found quite nice approach in JED editor sources (it is called
'Emacs locking' there, so maybe it is more universal):
/* The basic idea here is quite simple. Whenever a buffer is attached
to
* a file, and that buffer is modified, then attempt to lock the
* file. Moreover, before writing to a file for any reason, lock the
* file. The lock is really a protocol respected and not a real lock.
* The protocol is this: If in the directory of the file is a
* symbolic link with name ".#FILE", the FILE is considered to be locked
* by the process specified by the link.
*
* Here are the scenerios requiring a lock:
*
* 1. When a buffer attached to a file becomes modified.
* 2. When appending or writing to a file.
*
* Suppose that a buffer has not been modified but one appends a
* region of the buffer to some file. Then while that file is being
* written, it should be locked and then released when finished.
* However, suppose another buffer has that file locked. Then in
* order to write to it, either the lock must be stolen or ignored.
* In either of these cases, the user is responsible to what happens
* to the text in the other buffer. In fact, if the user elects to
* steal the lock from the other buffer, then that lock will be
* deleted after the file has been modfied. Of course these same
comments
* apply if another process owns the lock.
*
* Now consider the case when a buffer is modified and has the file
locked.
* When the buffer is saved, the file will already be locked and there
is no
* need to lock it again.
*/
Regards
Adam
--
_.|._ |_ _. : Adam Byrtek /alpha/
(_|||_)| |(_| : email alpha@(irc.pl|debian.org)
| : jabber alpha.pl(at)jabber.org, pgp 0xB25952C0
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]