aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-04-21 00:34:13 +0200
committerJustin M. Keyes <justinkz@gmail.com>2018-04-21 12:51:27 +0200
commit498731615c2f879c0b67323aba385c17a4a39d24 (patch)
tree0f0fbfa0a794b089718dd9c783fa7ea697639037
parenta02d22cca825f2c04381b40d50abfc7a15afec20 (diff)
downloadrneovim-498731615c2f879c0b67323aba385c17a4a39d24.tar.gz
rneovim-498731615c2f879c0b67323aba385c17a4a39d24.tar.bz2
rneovim-498731615c2f879c0b67323aba385c17a4a39d24.zip
IO: let 'fsync' option control more cases
Vim has the 'swapsync' option which we removed in 62d137ce0969. Instead let 'fsync' control swapfile-fsync. These cases ALWAYS force fsync (ignoring 'fsync' option): - Idle (CursorHold). - Exit caused by deadly signal. - SIGPWR signal. - Explicit :preserve command.
-rw-r--r--src/nvim/ex_docmd.c10
-rw-r--r--src/nvim/fileio.c2
-rw-r--r--src/nvim/getchar.c11
-rw-r--r--src/nvim/memline.c12
-rw-r--r--src/nvim/misc1.c2
-rw-r--r--src/nvim/os/signal.c2
6 files changed, 19 insertions, 20 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 7cd6dbdeca..7c857cde82 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -6547,18 +6547,14 @@ void alist_slash_adjust(void)
#endif
-/*
- * ":preserve".
- */
+/// ":preserve".
static void ex_preserve(exarg_T *eap)
{
curbuf->b_flags |= BF_PRESERVED;
- ml_preserve(curbuf, TRUE);
+ ml_preserve(curbuf, true, true);
}
-/*
- * ":recover".
- */
+/// ":recover".
static void ex_recover(exarg_T *eap)
{
/* Set recoverymode right away to avoid the ATTENTION prompt. */
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 4adff63b95..d96f5412ec 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -3068,7 +3068,7 @@ nobackup:
*/
if (reset_changed && !newfile && overwriting
&& !(exiting && backup != NULL)) {
- ml_preserve(buf, FALSE);
+ ml_preserve(buf, false, !!p_fs);
if (got_int) {
SET_ERRMSG(_(e_interr));
goto restore_backup;
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 98164b2653..3541ba7cc8 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -1347,14 +1347,17 @@ void before_blocking(void)
* All the changed memfiles are synced if c == 0 or when the number of typed
* characters reaches 'updatecount' and 'updatecount' is non-zero.
*/
-void updatescript(int c)
+static void updatescript(int c)
{
static int count = 0;
- if (c && scriptout)
+ if (c && scriptout) {
putc(c, scriptout);
- if (c == 0 || (p_uc > 0 && ++count >= p_uc)) {
- ml_sync_all(c == 0, TRUE);
+ }
+ bool idle = (c == 0);
+ if (idle || (p_uc > 0 && ++count >= p_uc)) {
+ ml_sync_all(idle, true,
+ (!!p_fs || idle)); // Always fsync at idle (CursorHold).
count = 0;
}
}
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index c11ca74f5c..dd80ec8d6a 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -1593,7 +1593,7 @@ static int recov_file_names(char_u **names, char_u *path, int prepend_dot)
* If 'check_char' is TRUE, stop syncing when character becomes available, but
* always sync at least one block.
*/
-void ml_sync_all(int check_file, int check_char)
+void ml_sync_all(int check_file, int check_char, bool do_fsync)
{
FOR_ALL_BUFFERS(buf) {
if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL)
@@ -1612,14 +1612,14 @@ void ml_sync_all(int check_file, int check_char)
if (!os_fileinfo((char *)buf->b_ffname, &file_info)
|| file_info.stat.st_mtim.tv_sec != buf->b_mtime_read
|| os_fileinfo_size(&file_info) != buf->b_orig_size) {
- ml_preserve(buf, FALSE);
+ ml_preserve(buf, false, do_fsync);
did_check_timestamps = FALSE;
need_check_timestamps = TRUE; /* give message later */
}
}
if (buf->b_ml.ml_mfp->mf_dirty) {
(void)mf_sync(buf->b_ml.ml_mfp, (check_char ? MFS_STOP : 0)
- | (bufIsChanged(buf) ? MFS_FLUSH : 0));
+ | (do_fsync && bufIsChanged(buf) ? MFS_FLUSH : 0));
if (check_char && os_char_avail()) /* character available now */
break;
}
@@ -1636,7 +1636,7 @@ void ml_sync_all(int check_file, int check_char)
*
* when message is TRUE the success of preserving is reported
*/
-void ml_preserve(buf_T *buf, int message)
+void ml_preserve(buf_T *buf, int message, bool do_fsync)
{
bhdr_T *hp;
linenr_T lnum;
@@ -1656,7 +1656,7 @@ void ml_preserve(buf_T *buf, int message)
ml_flush_line(buf); /* flush buffered line */
(void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush locked block */
- status = mf_sync(mfp, MFS_ALL | MFS_FLUSH);
+ status = mf_sync(mfp, MFS_ALL | (do_fsync ? MFS_FLUSH : 0));
/* stack is invalid after mf_sync(.., MFS_ALL) */
buf->b_ml.ml_stack_top = 0;
@@ -1686,7 +1686,7 @@ void ml_preserve(buf_T *buf, int message)
}
(void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush locked block */
/* sync the updated pointer blocks */
- if (mf_sync(mfp, MFS_ALL | MFS_FLUSH) == FAIL)
+ if (mf_sync(mfp, MFS_ALL | (do_fsync ? MFS_FLUSH : 0)) == FAIL)
status = FAIL;
buf->b_ml.ml_stack_top = 0; /* stack is invalid now */
}
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index b0232b6516..28455f0ba9 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -2643,7 +2643,7 @@ void preserve_exit(void)
if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) {
mch_errmsg((uint8_t *)"Vim: preserving files...\n");
ui_flush();
- ml_sync_all(false, false); // preserve all swap files
+ ml_sync_all(false, false, true); // preserve all swap files
break;
}
}
diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c
index 732be072e1..fc7f9cefd1 100644
--- a/src/nvim/os/signal.c
+++ b/src/nvim/os/signal.c
@@ -145,7 +145,7 @@ static void on_signal(SignalWatcher *handle, int signum, void *data)
case SIGPWR:
// Signal of a power failure(eg batteries low), flush the swap files to
// be safe
- ml_sync_all(false, false);
+ ml_sync_all(false, false, true);
break;
#endif
#ifdef SIGPIPE