bug-sed
[Top][All Lists]
Advanced

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

bug#27200: sed happily modifies read-only files.


From: Davide Brini
Subject: bug#27200: sed happily modifies read-only files.
Date: Wed, 7 Jun 2017 22:53:09 +0200

On Wed, 7 Jun 2017 17:39:45 +0000, Assaf Gordon <address@hidden>
wrote:

> >When trying to insert something: "W10: Warning: Changing a readonly file"
> >When trying to save the file: "[RED] E45: 'readonly' option is set
> >(add ! to override)"  
> 
> Exactly! "add ! to override" means VI can replace that file.
> 
> When you use "w!" in VI,
> VI *can not* replace the content of the existing file (the kernel 
> prevents it). But it can create a new temporary file,
> then replace the source file with it.
>
> ...
> 
> VI *replaced* the file, it did not (and could not) modify
> the file directly.


(side note that does not change the point being made)

That might be what vi does; I believe that vim, instead, when using "w!",
changes the permissions to add +w, writes, then changes the permissions
back to remove the write permission (of course the user must have the
right to do all that). This way the inode is preserved.

Strace seems to confirm that:

("foo" is a "-r--r--r--" file)

...
chmod("foo", 0100644)                   = 0
...
open("foo", O_WRONLY|O_CREAT|O_TRUNC, 0644) = 4
write(4, "djfhdjdjfjhfjhjkfhdkkjjfhjk\n", 28) = 28
fsync(4)                                = 0
close(4)                                = 0
chmod("foo", 0100444)                   = 0
...


-- 
D.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]