Skip to content

Commit

Permalink
patch 8.1.0161: buffer not updated with 'autoread' set if file was de…
Browse files Browse the repository at this point in the history
…leted

Problem:    Buffer not updated with 'autoread' set if file was deleted.
            (Michael Naumann)
Solution:   Don't set the timestamp to zero. (closes #3165)
  • Loading branch information
brammool committed Jul 7, 2018
1 parent cbbe4ab commit 386bc82
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/fileio.c
Expand Up @@ -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;
}
Expand Down
56 changes: 50 additions & 6 deletions src/testdir/test_stat.vim
Expand Up @@ -46,19 +46,23 @@ 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'

let fl = ['Hello World!']
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)
Expand All @@ -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'

Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -789,6 +789,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
161,
/**/
160,
/**/
Expand Down

0 comments on commit 386bc82

Please sign in to comment.