patch 8.0.1305: writefile() never calls fsync()
Problem: Writefile() never calls fsync().
Solution: Follow the 'fsync' option with override to enable or disable.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 1991aa7..25b28bb 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -13348,6 +13348,9 @@
{
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 @@
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 @@
{
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);
}