52907Re: Race condition during file saving
- Jan 4, 2009Nikolai Weibull wrote:
> On Sun, Jan 4, 2009 at 16:26, Adam Osuchowski <adwol@...> wrote:If you're talking Unix/Linux/etc -- flock is a cooperative file locking
>> Nikolai Weibull wrote:
>>> I haven't really understood what the problem is (I don't believe that
>>> there actually is one),
>> There is a non-zero time period between open file and write complete
>> content. Because vim truncate file while opening (O_TRUNC), another
>> process which would like to read it can hit in the moment when file will
>> be empty.
> Yeah, so? That's not a bug. File systems are, generally, not
> databases with ACID properties. They don't provide transactions (at
> the level we're discussing).
>>> but would opening the file exclusively solve the problem?
>> Do you mean O_EXCL flag to open syscall? It doesn't protect against
>> such a situation. It only guarantee that file doesn't exist prior to
>> call open in atomic manner.
> No, I mean both O_EXCL (so that a file hasn't been created in between
> the time the original file has been renamed and the new one opened - a
> case so far not mentioned (or?)) and flock:ing it (but, as I
> understand from the man page, this doesn't seem to be very interesting
mechanism, and processes which ignore it are not impeded.
Look into mandatory file locking (the mand option to mount). Mandatory
file locking is kernel enforced, and not even root apparently
can force its way through.
Mandatory file locking by vim would not be practical, as it generally
requires root access to set up, and only involves files on the
mandatory-filelocking mounted device.
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
- << Previous post in topic Next post in topic >>