summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-07-07 18:34:12 +0200
committerBram Moolenaar <Bram@vim.org>2018-07-07 18:34:12 +0200
commit386bc82a3f82f70bad75aaad74dba57a176b5840 (patch)
tree177a917fd9287fd0c92e74607b85bb42d1ad4fde
parentcbbe4ab4b27a2060506fcd2427aed8d8fbff1a21 (diff)
downloadvim-git-386bc82a3f82f70bad75aaad74dba57a176b5840.tar.gz
patch 8.1.0161: buffer not updated with 'autoread' set if file was deletedv8.1.0161
Problem: Buffer not updated with 'autoread' set if file was deleted. (Michael Naumann) Solution: Don't set the timestamp to zero. (closes #3165)
-rw-r--r--src/fileio.c8
-rw-r--r--src/testdir/test_stat.vim56
-rw-r--r--src/version.c2
3 files changed, 57 insertions, 9 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 0c56a1ef0..07b241ece 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -6923,11 +6923,13 @@ buf_check_timestamp(
{
retval = 1;
- /* set b_mtime to stop further warnings (e.g., when executing
- * FileChangedShell autocmd) */
+ // set b_mtime to stop further warnings (e.g., when executing
+ // FileChangedShell autocmd)
if (stat_res < 0)
{
- buf->b_mtime = 0;
+ // When 'autoread' is set we'll check the file again to see if it
+ // re-appears.
+ buf->b_mtime = buf->b_p_ar;
buf->b_orig_size = 0;
buf->b_orig_mode = 0;
}
diff --git a/src/testdir/test_stat.vim b/src/testdir/test_stat.vim
index de5fac46f..307cf5e64 100644
--- a/src/testdir/test_stat.vim
+++ b/src/testdir/test_stat.vim
@@ -46,6 +46,15 @@ func Test_existent_directory()
call assert_equal('rwx', getfperm(dname)[0:2])
endfunc
+func SleepForTimestamp()
+ " FAT has a granularity of 2 seconds, otherwise it's usually 1 second
+ if has('win32')
+ sleep 2
+ else
+ sleep 1
+ endif
+endfunc
+
func Test_checktime()
let fname = 'Xtest.tmp'
@@ -53,12 +62,7 @@ func Test_checktime()
call writefile(fl, fname)
set autoread
exec 'e' fname
- " FAT has a granularity of 2 seconds, otherwise it's usually 1 second
- if has('win32')
- sleep 2
- else
- sleep 1
- endif
+ call SleepForTimestamp()
let fl = readfile(fname)
let fl[0] .= ' - checktime'
call writefile(fl, fname)
@@ -68,6 +72,46 @@ func Test_checktime()
call delete(fname)
endfunc
+func Test_autoread_file_deleted()
+ new Xautoread
+ set autoread
+ call setline(1, 'original')
+ w!
+
+ call SleepForTimestamp()
+ if has('win32')
+ silent !echo changed > Xautoread
+ else
+ silent !echo 'changed' > Xautoread
+ endif
+ checktime
+ call assert_equal('changed', trim(getline(1)))
+
+ call SleepForTimestamp()
+ messages clear
+ if has('win32')
+ silent !del Xautoread
+ else
+ silent !rm Xautoread
+ endif
+ checktime
+ call assert_match('E211:', execute('messages'))
+ call assert_equal('changed', trim(getline(1)))
+
+ call SleepForTimestamp()
+ if has('win32')
+ silent !echo recreated > Xautoread
+ else
+ silent !echo 'recreated' > Xautoread
+ endif
+ checktime
+ call assert_equal('recreated', trim(getline(1)))
+
+ call delete('Xautoread')
+ bwipe!
+endfunc
+
+
func Test_nonexistent_file()
let fname = 'Xtest.tmp'
diff --git a/src/version.c b/src/version.c
index cb6d2c8f5..affeeb224 100644
--- a/src/version.c
+++ b/src/version.c
@@ -790,6 +790,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 161,
+/**/
160,
/**/
159,