Re: mcedit file locking



Hello, Adam!

> > Why do you think we need file locking in the editor?  It's not an often
> > requested feature.  What kind of scenarios do you want to prevent?  Do we
> > need write locks or read locks?

This question still needs to be answered.

> I just wanted to start work on the following TODO item:
>
> "Lock files in the editor to prevent opening them more than once.
> Warn user when opening locked file."
>
> Did I misunderstand something?

No, it was me :-)

OK, we have several possibilities:

1) mc-specific, user-specific file locks using O_EXCL.  Lock files should
probably go to /tmp/mc-$USER.

Pro: Other software is not affected.  Fully portable (even RCS uses it).
Works in non-writable directories.

Con: Stale locks may be left under /tmp/mc-$USER is mc is killed.  Locking
between users may be desired in some cases.

2) mc-specific, non-user-specific file locks.  Created in the same
directory as the file being edited.

Pro: other software is not affected.  Fully portable.

Con: Stale locks may be left everywhere, copied together with directories.
Doesn't work in non-writable directories.

3) System-wide locks using fcntl() or (if not supported) flock().

Pro: No stale locks.  Works in non-writable directories.  Locking between
users.

Con: not 100% portable, but should work on most modern systems.  Locks
affect other software.

We can also use combinations of the above, e.g. fcntl() on file locks.
If the fcntl() lock can be obtained on an existing file lock, it's
assumed to be a stale lock.

To make a choice, we need to answer a few questions.

Should the lock be held for the whole time when the file is being edited
or just for the time when it's being saved?  If we take the later
approach, the user will have a chance to save the file under another name
in the editor that is closed last.

Do we want the locks to affect other software?  I just checked, support
for fcntl() in vim 6.1 is planned, but it's not there yet.  cooledit
3.17.6 doesn't seem to use fcntl() for locking.  Most importantly, I'm not
sure if we want other software (like procmail) to wait for the mc lock,
even if I'm reading the mail in the editor.

Do we want locks to be shared between users?  Of course the locks should
not be mandatory, but I'm not sure if we want e.g. root to be affected by
users' locks at all.

With all that complexity I feel that we probably should postpone the issue
or find a popular editor that used locking already and implement locking
in a compatible way.

-- 
Regards,
Pavel Roskin



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]