aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-04-01 21:13:21 +0300
committerZyX <kp-pav@yandex.ru>2017-04-01 21:15:13 +0300
commitcc4523013f8e693f92de3b96ff36065895c60974 (patch)
treea1a1fe698d7e958099b4c6454f8cafcf0f40ff58
parent8de53157b691dd4ce604a5be0e2d9c3b6014bfdb (diff)
downloadrneovim-cc4523013f8e693f92de3b96ff36065895c60974.tar.gz
rneovim-cc4523013f8e693f92de3b96ff36065895c60974.tar.bz2
rneovim-cc4523013f8e693f92de3b96ff36065895c60974.zip
eval,fileio: Omit additional fsync() call
Fixes #6420
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/os/fileio.c31
-rw-r--r--test/unit/os/fileio_spec.lua19
3 files changed, 43 insertions, 9 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 15b712e7de..a6774a3a0b 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -17289,7 +17289,7 @@ static bool write_list(FileDescriptor *const fp, const list_T *const list,
}
}
}
- if ((error = file_fsync(fp)) != 0) {
+ if ((error = file_flush(fp)) != 0) {
goto write_list_error;
}
return true;
diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c
index 775f2bd449..3c928363cc 100644
--- a/src/nvim/os/fileio.c
+++ b/src/nvim/os/fileio.c
@@ -143,21 +143,36 @@ int file_free(FileDescriptor *const fp) FUNC_ATTR_NONNULL_ALL
/// @param[in,out] fp File to work with.
///
/// @return 0 or error code.
-int file_fsync(FileDescriptor *const fp)
+int file_flush(FileDescriptor *const fp)
FUNC_ATTR_NONNULL_ALL
{
if (!fp->wr) {
return 0;
}
file_rb_write_full_cb(fp->rv, fp);
- if (fp->_error != 0) {
- const int error = fp->_error;
- fp->_error = 0;
- return error;
+ const int error = fp->_error;
+ fp->_error = 0;
+ return error;
+}
+
+/// Flush file modifications to disk and run fsync()
+///
+/// @param[in,out] fp File to work with.
+///
+/// @return 0 or error code.
+int file_fsync(FileDescriptor *const fp)
+ FUNC_ATTR_NONNULL_ALL
+{
+ if (!fp->wr) {
+ return 0;
}
- const int error = os_fsync(fp->fd);
- if (error != UV_EINVAL && error != UV_EROFS) {
- return error;
+ const int flush_error = file_flush(fp);
+ if (flush_error != 0) {
+ return flush_error;
+ }
+ const int fsync_error = os_fsync(fp->fd);
+ if (fsync_error != UV_EINVAL && fsync_error != UV_EROFS) {
+ return fsync_error;
}
return 0;
}
diff --git a/test/unit/os/fileio_spec.lua b/test/unit/os/fileio_spec.lua
index 7a738ce85c..5e1b2523fa 100644
--- a/test/unit/os/fileio_spec.lua
+++ b/test/unit/os/fileio_spec.lua
@@ -80,6 +80,10 @@ local function file_read(fp, size)
return ret1, ret2
end
+local function file_flush(fp)
+ return m.file_flush(fp)
+end
+
local function file_fsync(fp)
return m.file_fsync(fp)
end
@@ -244,6 +248,21 @@ describe('file_fsync', function()
end)
end)
+describe('file_flush', function()
+ itp('can flush writes to disk', function()
+ local err, fp = file_open(filec, m.kFileCreateOnly, 384)
+ eq(0, file_flush(fp))
+ eq(0, err)
+ eq(0, lfs.attributes(filec).size)
+ local wsize = file_write(fp, 'test')
+ eq(4, wsize)
+ eq(0, lfs.attributes(filec).size)
+ eq(0, file_flush(fp))
+ eq(wsize, lfs.attributes(filec).size)
+ eq(0, m.file_close(fp))
+ end)
+end)
+
describe('file_read', function()
itp('can read small chunks of input until eof', function()
local err, fp = file_open(file1, 0, 384)