vim-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 vim/vim#3165)
386bc82a3f

Sleep 2 seconds for autoread (https://github.com/neovim/neovim/pull/7592).
This commit is contained in:
Jan Edmund Lazo 2018-08-13 06:59:30 -04:00
parent ee5cc88a73
commit e346c01c31
2 changed files with 55 additions and 9 deletions

View File

@ -4892,10 +4892,12 @@ buf_check_timestamp (
)) { )) {
retval = 1; retval = 1;
/* set b_mtime to stop further warnings (e.g., when executing // set b_mtime to stop further warnings (e.g., when executing
* FileChangedShell autocmd) */ // FileChangedShell autocmd)
if (!file_info_ok) { if (!file_info_ok) {
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_size = 0;
buf->b_orig_mode = 0; buf->b_orig_mode = 0;
} else { } else {

View File

@ -46,6 +46,15 @@ func Test_existent_directory()
call assert_equal('rwx', getfperm(dname)[0:2]) call assert_equal('rwx', getfperm(dname)[0:2])
endfunc endfunc
func SleepForTimestamp()
" FAT has a granularity of 2 seconds, otherwise it's usually 1 second
if has('win32')
sleep 2
else
sleep 2
endif
endfunc
func Test_checktime() func Test_checktime()
let fname = 'Xtest.tmp' let fname = 'Xtest.tmp'
@ -53,12 +62,7 @@ func Test_checktime()
call writefile(fl, fname) call writefile(fl, fname)
set autoread set autoread
exec 'e' fname exec 'e' fname
" FAT has a granularity of 2 seconds, otherwise it's usually 1 second call SleepForTimestamp()
if has('win32')
sleep 2
else
sleep 2
endif
let fl = readfile(fname) let fl = readfile(fname)
let fl[0] .= ' - checktime' let fl[0] .= ' - checktime'
call writefile(fl, fname) call writefile(fl, fname)
@ -68,6 +72,46 @@ func Test_checktime()
call delete(fname) call delete(fname)
endfunc 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() func Test_nonexistent_file()
let fname = 'Xtest.tmp' let fname = 'Xtest.tmp'