Jan Vroonhof writes:
Charles G Waldman <cgw(a)pgt.com> writes:
> Changing src/sysfile to read
> #if defined (LINUX) || !defined (USG) && !defined(WINDOWSNT)
>
> causes the fsync to be done, and makes the problem go away.
Since there is no real need to do the fsync since this seems the wrong
solution. Also it is a platform-specific decision.
I agree about this as a solution for this particular problem,
but doing an fsync() is good, if you can, for crash protection.
The normal save procedure is
1. Overwrite the buffer's file.
2. Unlink the autosave file.
If all the blocks from step 1 haven't hit the disk before step 2
happens, then a subsequent system or Emacs crash might leave you
with a truncated disk file and no autosave file. So if Linux has
fsync(), we should notice it and use it.
> Fix #2: Change order of close and stat
This would seem to be the correct solution. On other systems it should
not make any difference. The only thing is, why wasn't it done before?
stat() is relatively expensive compared to fstat(). Also, it
is surprising (to me) that close() would fiddle with the file
modtime, given that close() does no implicit flushing of data.