mirror of
https://github.com/vim/vim.git
synced 2025-10-15 07:14:09 -04:00
patch 8.0.1305: writefile() never calls fsync()
Problem: Writefile() never calls fsync(). Solution: Follow the 'fsync' option with override to enable or disable.
This commit is contained in:
@@ -13348,6 +13348,9 @@ f_writefile(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
int binary = FALSE;
|
||||
int append = FALSE;
|
||||
#ifdef HAVE_FSYNC
|
||||
int do_fsync = p_fs;
|
||||
#endif
|
||||
char_u *fname;
|
||||
FILE *fd;
|
||||
int ret = 0;
|
||||
@@ -13380,6 +13383,12 @@ f_writefile(typval_T *argvars, typval_T *rettv)
|
||||
binary = TRUE;
|
||||
if (vim_strchr(arg2, 'a') != NULL)
|
||||
append = TRUE;
|
||||
#ifdef HAVE_FSYNC
|
||||
if (vim_strchr(arg2, 's') != NULL)
|
||||
do_fsync = TRUE;
|
||||
else if (vim_strchr(arg2, 'S') != NULL)
|
||||
do_fsync = FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
fname = get_tv_string_chk(&argvars[1]);
|
||||
@@ -13398,6 +13407,10 @@ f_writefile(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
if (write_list(fd, list, binary) == FAIL)
|
||||
ret = -1;
|
||||
#ifdef HAVE_FSYNC
|
||||
else if (do_fsync && fsync(fileno(fd)) != 0)
|
||||
EMSG(_(e_fsync));
|
||||
#endif
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user