Mercurial > vim
diff src/evalfunc.c @ 12857:ffdf2e4b5d9a v8.0.1305
patch 8.0.1305: writefile() never calls fsync()
commit https://github.com/vim/vim/commit/7567d0b115e332f61a9f390aaccdf7825b891227
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 16 23:04:15 2017 +0100
patch 8.0.1305: writefile() never calls fsync()
Problem: Writefile() never calls fsync().
Solution: Follow the 'fsync' option with override to enable or disable.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 16 Nov 2017 23:15:05 +0100 |
parents | 963cdeb42c41 |
children | ebb4f6c93598 |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -13348,6 +13348,9 @@ f_writefile(typval_T *argvars, typval_T { 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 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 { 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); }