Skip to content

Commit 386bc82

Browse files
committed
patch 8.1.0161: buffer not updated with 'autoread' set if file was deleted
Problem: Buffer not updated with 'autoread' set if file was deleted. (Michael Naumann) Solution: Don't set the timestamp to zero. (closes #3165)
1 parent cbbe4ab commit 386bc82

3 files changed

Lines changed: 57 additions & 9 deletions

File tree

‎src/fileio.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6923,11 +6923,13 @@ buf_check_timestamp(
69236923
{
69246924
retval = 1;
69256925

6926-
/* set b_mtime to stop further warnings (e.g., when executing
6927-
* FileChangedShell autocmd) */
6926+
// set b_mtime to stop further warnings (e.g., when executing
6927+
// FileChangedShell autocmd)
69286928
if (stat_res < 0)
69296929
{
6930-
buf->b_mtime = 0;
6930+
// When 'autoread' is set we'll check the file again to see if it
6931+
// re-appears.
6932+
buf->b_mtime = buf->b_p_ar;
69316933
buf->b_orig_size = 0;
69326934
buf->b_orig_mode = 0;
69336935
}

‎src/testdir/test_stat.vim‎

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ func Test_existent_directory()
4646
call assert_equal('rwx', getfperm(dname)[0:2])
4747
endfunc
4848

49+
func SleepForTimestamp()
50+
" FAT has a granularity of 2 seconds, otherwise it's usually 1 second
51+
if has('win32')
52+
sleep 2
53+
else
54+
sleep 1
55+
endif
56+
endfunc
57+
4958
func Test_checktime()
5059
let fname = 'Xtest.tmp'
5160

5261
let fl = ['Hello World!']
5362
call writefile(fl, fname)
5463
set autoread
5564
exec 'e' fname
56-
" FAT has a granularity of 2 seconds, otherwise it's usually 1 second
57-
if has('win32')
58-
sleep 2
59-
else
60-
sleep 1
61-
endif
65+
call SleepForTimestamp()
6266
let fl = readfile(fname)
6367
let fl[0] .= ' - checktime'
6468
call writefile(fl, fname)
@@ -68,6 +72,46 @@ func Test_checktime()
6872
call delete(fname)
6973
endfunc
7074

75+
func Test_autoread_file_deleted()
76+
new Xautoread
77+
set autoread
78+
call setline(1, 'original')
79+
w!
80+
81+
call SleepForTimestamp()
82+
if has('win32')
83+
silent !echo changed > Xautoread
84+
else
85+
silent !echo 'changed' > Xautoread
86+
endif
87+
checktime
88+
call assert_equal('changed', trim(getline(1)))
89+
90+
call SleepForTimestamp()
91+
messages clear
92+
if has('win32')
93+
silent !del Xautoread
94+
else
95+
silent !rm Xautoread
96+
endif
97+
checktime
98+
call assert_match('E211:', execute('messages'))
99+
call assert_equal('changed', trim(getline(1)))
100+
101+
call SleepForTimestamp()
102+
if has('win32')
103+
silent !echo recreated > Xautoread
104+
else
105+
silent !echo 'recreated' > Xautoread
106+
endif
107+
checktime
108+
call assert_equal('recreated', trim(getline(1)))
109+
110+
call delete('Xautoread')
111+
bwipe!
112+
endfunc
113+
114+
71115
func Test_nonexistent_file()
72116
let fname = 'Xtest.tmp'
73117

‎src/version.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ static char *(features[]) =
789789

790790
static int included_patches[] =
791791
{ /* Add new patch number below this line */
792+
/**/
793+
161,
792794
/**/
793795
160,
794796
/**/

0 commit comments

Comments
 (0)