mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.1.1349: if writing runs into conversion error backup file is deleted
Problem: If writing runs into a conversion error the backup file is
deleted. (Arseny Nasokin)
Solution: Don't delete the backup file is the file was overwritten and a
conversion error occurred. (Christian Brabandt, closes vim/vim#4387)
cf0bfd9ade
This commit is contained in:
parent
f286af170d
commit
d07a6e2b45
@ -3693,9 +3693,11 @@ restore_backup:
|
|||||||
/*
|
/*
|
||||||
* Remove the backup unless 'backup' option is set
|
* 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"));
|
EMSG(_("E207: Can't delete backup file"));
|
||||||
|
}
|
||||||
|
|
||||||
goto nofail;
|
goto nofail;
|
||||||
|
|
||||||
|
@ -36,13 +36,15 @@ func Test_writefile_fails_conversion()
|
|||||||
if !has('multi_byte') || !has('iconv')
|
if !has('multi_byte') || !has('iconv')
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
" Without a backup file the write won't happen if there is a conversion
|
||||||
|
" error.
|
||||||
set nobackup nowritebackup
|
set nobackup nowritebackup
|
||||||
new
|
new
|
||||||
let contents = ["line one", "line two"]
|
let contents = ["line one", "line two"]
|
||||||
call writefile(contents, 'Xfile')
|
call writefile(contents, 'Xfile')
|
||||||
edit Xfile
|
edit Xfile
|
||||||
call setline(1, ["first line", "cannot convert \u010b", "third line"])
|
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 assert_equal(contents, readfile('Xfile'))
|
||||||
|
|
||||||
call delete('Xfile')
|
call delete('Xfile')
|
||||||
@ -50,6 +52,27 @@ func Test_writefile_fails_conversion()
|
|||||||
set backup& writebackup&
|
set backup& writebackup&
|
||||||
endfunc
|
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)
|
func SetFlag(timer)
|
||||||
let g:flag = 1
|
let g:flag = 1
|
||||||
endfunc
|
endfunc
|
||||||
|
Loading…
Reference in New Issue
Block a user