[BUG] vi does not recognize changed permissions on read only files

Rich Felker dalias at aerifal.cx
Thu Oct 11 03:04:34 UTC 2012


On Thu, Oct 11, 2012 at 03:16:28AM +0200, Harald Becker wrote:
> Hi Jim !
> 
> >Normally, in an editor, you do NOT do this.  Consider what happens
> >if, behind the scenes, somebody did an "rm file".  Your hours of
> >typing would go into a still-open file, to an anonymous inode, and
> >then quietly disappear.
> 
> .... which I call correct behavior! If someone removed the file you are
> currently editing this shall have a reason.

Well you'll find you're pretty lonely. In fact, most people find the
opposite extreme to be correct: always writing to a temporary file,
and renaming the temporary file over top of the original. This ensures
atomicity of the save, so that data won't be lost if your process is
killed while saving, and so that other processes reading the file will
never see a partially-written file.

Of course this also has down-sides, such as losing extended attributes
and other file properties the application is not aware of, and not
being able to preserve ownership. That's why most programs by default
do what busybox vi is doing.

> >This would not work if you'd held the FD open all that time.
> 
> Holding FD open is the indicator to many systems (especially network
> file systems) that someone is working at the file and some kind
> of locking shall be done. That is no one else shall modify the files
> contents while you are working at it.

There is no precedent for this interpretation. Open file descriptions
are not locks.

Rich


More information about the busybox mailing list