aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2016-01-01 12:13:40 -0500
committerJustin M. Keyes <justinkz@gmail.com>2016-01-01 12:13:40 -0500
commitdf4ac79761162313de4e27a265044125062013cf (patch)
treef29cc5366be73b1ec58e29e0cb50b407b27a1e8c /src
parenta79ebeeea469958a2f56096dcfc878da7cf790d6 (diff)
parent648aebb8b6dcf28c85477398572e5552062ceb18 (diff)
downloadrneovim-df4ac79761162313de4e27a265044125062013cf.tar.gz
rneovim-df4ac79761162313de4e27a265044125062013cf.tar.bz2
rneovim-df4ac79761162313de4e27a265044125062013cf.zip
Merge pull request #3911 from sethjackson/have-fsync-guard
os_fsync
Diffstat (limited to 'src')
-rw-r--r--src/nvim/fileio.c20
-rw-r--r--src/nvim/memfile.c24
-rw-r--r--src/nvim/option_defs.h40
-rw-r--r--src/nvim/options.lua1
-rw-r--r--src/nvim/os/fs.c13
-rw-r--r--src/nvim/shada.c4
6 files changed, 46 insertions, 56 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 1a6c85abaa..58269983c5 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -3368,16 +3368,16 @@ restore_backup:
nchars += len;
}
-#if defined(UNIX) && defined(HAVE_FSYNC)
- /* On many journalling file systems there is a bug that causes both the
- * original and the backup file to be lost when halting the system right
- * after writing the file. That's because only the meta-data is
- * journalled. Syncing the file slows down the system, but assures it has
- * been written to disk and we don't lose it.
- * For a device do try the fsync() but don't complain if it does not work
- * (could be a pipe).
- * If the 'fsync' option is FALSE, don't fsync(). Useful for laptops. */
- if (p_fs && fsync(fd) != 0 && !device) {
+#if defined(UNIX)
+ // On many journalling file systems there is a bug that causes both the
+ // original and the backup file to be lost when halting the system right
+ // after writing the file. That's because only the meta-data is
+ // journalled. Syncing the file slows down the system, but assures it has
+ // been written to disk and we don't lose it.
+ // For a device do try the fsync() but don't complain if it does not work
+ // (could be a pipe).
+ // If the 'fsync' option is FALSE, don't fsync(). Useful for laptops.
+ if (p_fs && os_fsync(fd) != 0 && !device) {
errmsg = (char_u *)_("E667: Fsync failed");
end = 0;
}
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c
index 3df4cbc4a3..9f5e4247b5 100644
--- a/src/nvim/memfile.c
+++ b/src/nvim/memfile.c
@@ -460,31 +460,11 @@ int mf_sync(memfile_T *mfp, int flags)
mfp->mf_dirty = false;
if ((flags & MFS_FLUSH) && *p_sws != NUL) {
-#if defined(UNIX)
-# ifdef HAVE_FSYNC
if (STRCMP(p_sws, "fsync") == 0) {
- if (fsync(mfp->mf_fd))
+ if (os_fsync(mfp->mf_fd)) {
status = FAIL;
- } else {
-# endif
- // OpenNT is strictly POSIX (Benzinger).
- // Tandem/Himalaya NSK-OSS doesn't have sync()
-# if defined(__OPENNT) || defined(__TANDEM)
- fflush(NULL);
-# else
- sync();
-# endif
-# ifdef HAVE_FSYNC
+ }
}
-# endif
-#endif
-# ifdef SYNC_DUP_CLOSE
- // Win32 is a bit more work: Duplicate the file handle and close it.
- // This should flush the file to disk.
- int fd;
- if ((fd = dup(mfp->mf_fd)) >= 0)
- close(fd);
-# endif
}
got_int |= got_int_save;
diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h
index c72e1cf0bb..938aa9bc83 100644
--- a/src/nvim/option_defs.h
+++ b/src/nvim/option_defs.h
@@ -405,27 +405,25 @@ static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent",
# define FDO_INSERT 0x100
# define FDO_UNDO 0x200
# define FDO_JUMP 0x400
-EXTERN char_u *p_fp; /* 'formatprg' */
-#ifdef HAVE_FSYNC
-EXTERN int p_fs; /* 'fsync' */
-#endif
-EXTERN int p_gd; /* 'gdefault' */
-EXTERN char_u *p_pdev; /* 'printdevice' */
-EXTERN char_u *p_penc; /* 'printencoding' */
-EXTERN char_u *p_pexpr; /* 'printexpr' */
-EXTERN char_u *p_pmfn; /* 'printmbfont' */
-EXTERN char_u *p_pmcs; /* 'printmbcharset' */
-EXTERN char_u *p_pfn; /* 'printfont' */
-EXTERN char_u *p_popt; /* 'printoptions' */
-EXTERN char_u *p_header; /* 'printheader' */
-EXTERN int p_prompt; /* 'prompt' */
-EXTERN char_u *p_guicursor; /* 'guicursor' */
-EXTERN char_u *p_hf; /* 'helpfile' */
-EXTERN long p_hh; /* 'helpheight' */
-EXTERN char_u *p_hlg; /* 'helplang' */
-EXTERN int p_hid; /* 'hidden' */
-/* Use P_HID to check if a buffer is to be hidden when it is no longer
- * visible in a window. */
+EXTERN char_u *p_fp; // 'formatprg'
+EXTERN int p_fs; // 'fsync'
+EXTERN int p_gd; // 'gdefault'
+EXTERN char_u *p_pdev; // 'printdevice'
+EXTERN char_u *p_penc; // 'printencoding'
+EXTERN char_u *p_pexpr; // 'printexpr'
+EXTERN char_u *p_pmfn; // 'printmbfont'
+EXTERN char_u *p_pmcs; // 'printmbcharset'
+EXTERN char_u *p_pfn; // 'printfont'
+EXTERN char_u *p_popt; // 'printoptions'
+EXTERN char_u *p_header; // 'printheader'
+EXTERN int p_prompt; // 'prompt'
+EXTERN char_u *p_guicursor; // 'guicursor'
+EXTERN char_u *p_hf; // 'helpfile'
+EXTERN long p_hh; // 'helpheight'
+EXTERN char_u *p_hlg; // 'helplang'
+EXTERN int p_hid; // 'hidden'
+// Use P_HID to check if a buffer is to be hidden when it is no longer
+// visible in a window.
# define P_HID(buf) (buf_hide(buf))
EXTERN char_u *p_hl; /* 'highlight' */
EXTERN int p_hls; /* 'hlsearch' */
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 5187340629..e485b90394 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -959,7 +959,6 @@ return {
type='bool', scope={'global'},
secure=true,
vi_def=true,
- enable_if='HAVE_FSYNC',
varname='p_fs',
defaults={if_true={vi=true}}
},
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index d59b66e773..1a4c3495f2 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -202,6 +202,19 @@ int os_open(const char* path, int flags, int mode)
return r;
}
+/// Flushes file modifications to disk.
+///
+/// @param fd the file descriptor of the file to flush to disk.
+///
+/// @return `0` on success, a libuv error code on failure.
+int os_fsync(int fd)
+{
+ uv_fs_t fsync_req;
+ int r = uv_fs_fsync(&fs_loop, &fsync_req, fd, NULL);
+ uv_fs_req_cleanup(&fsync_req);
+ return r;
+}
+
/// Get stat information for a file.
///
/// @return libuv return code.
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index 42e514aa95..6a30472a7c 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -761,9 +761,9 @@ static void close_sd_writer(ShaDaWriteDef *const sd_writer)
FUNC_ATTR_NONNULL_ALL
{
const int fd = (int)(intptr_t) sd_writer->cookie;
- if (fsync(fd) < 0) {
+ if (os_fsync(fd) < 0) {
emsg2(_(SERR "System error while synchronizing ShaDa file: %s"),
- strerror(errno));
+ os_strerror(errno));
errno = 0;
}
close_file(fd);