vim-patch:8.2.3509: undo file is not synced (#23371)

Problem:    Undo file is not synced. (Sami Farin)
Solution:   Sync the undo file if 'fsync' is set. (Christian Brabandt,
            closes vim/vim#8879, closes vim/vim#8920)

340dd0fbe4

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2023-04-28 21:07:00 +08:00 committed by GitHub
parent 4f235e3caf
commit 715587f8e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -2774,8 +2774,8 @@ A jump table for the options with a short description can be found at |Q_op|.
'fsync' 'fs' boolean (default off)
global
When on, the OS function fsync() will be called after saving a file
(|:write|, |writefile()|, …), |swap-file| and |shada-file|. This
flushes the file to disk, ensuring that it is safely written.
(|:write|, |writefile()|, …), |swap-file|, |undo-persistence| and |shada-file|.
This flushes the file to disk, ensuring that it is safely written.
Slow on some systems: writing buffers, quitting Nvim, and other
operations may sometimes take a few seconds.

View File

@ -1333,6 +1333,10 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf,
}
#endif
if (p_fs && fflush(fp) == 0 && os_fsync(fd) != 0) {
write_ok = false;
}
write_error:
fclose(fp);
if (!write_ok) {