diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/fileio.c | 6 | ||||
| -rw-r--r-- | src/nvim/testdir/test_writefile.vim | 25 | 
2 files changed, 28 insertions, 3 deletions
| diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 507bf3c032..8e4a210b66 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -3693,9 +3693,11 @@ restore_backup:    /*     * Remove the backup unless 'backup' option is set     */ -  if (!p_bk && backup != NULL && os_remove((char *)backup) != 0) +  if (!p_bk && backup != NULL +      && !write_info.bw_conv_error +      && os_remove((char *)backup) != 0) {      EMSG(_("E207: Can't delete backup file")); - +  }    goto nofail; diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 1cd5fb306a..b4585a72ef 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -36,13 +36,15 @@ func Test_writefile_fails_conversion()    if !has('multi_byte') || !has('iconv')      return    endif +  " Without a backup file the write won't happen if there is a conversion +  " error.    set nobackup nowritebackup    new    let contents = ["line one", "line two"]    call writefile(contents, 'Xfile')    edit Xfile    call setline(1, ["first line", "cannot convert \u010b", "third line"]) -  call assert_fails('write ++enc=cp932') +  call assert_fails('write ++enc=cp932', 'E513:')    call assert_equal(contents, readfile('Xfile'))    call delete('Xfile') @@ -50,6 +52,27 @@ func Test_writefile_fails_conversion()    set backup& writebackup&  endfunc +func Test_writefile_fails_conversion2() +  if !has('iconv') || has('sun') +    return +  endif +  " With a backup file the write happens even if there is a conversion error, +  " but then the backup file must remain +  set nobackup writebackup +  let contents = ["line one", "line two"] +  call writefile(contents, 'Xfile_conversion_err') +  edit Xfile_conversion_err +  call setline(1, ["first line", "cannot convert \u010b", "third line"]) +  set fileencoding=latin1 +  let output = execute('write') +  call assert_match('CONVERSION ERROR', output) +  call assert_equal(contents, readfile('Xfile_conversion_err~')) + +  call delete('Xfile_conversion_err') +  call delete('Xfile_conversion_err~') +  bwipe! +endfunc +  func SetFlag(timer)    let g:flag = 1  endfunc | 
