Patch 8.1.1349
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 #4387)
Files: src/fileio.c, src/testdir/test_writefile.vim
*** ../vim-8.1.1348/src/fileio.c 2019-04-28 22:25:03.244480028 +0200
--- src/fileio.c 2019-05-18 18:39:15.668980172 +0200
***************
*** 4985,4994 ****
}
}
! /*
! * Remove the backup unless 'backup' option is set
! */
! if (!p_bk && backup != NULL && mch_remove(backup) != 0)
emsg(_("E207: Can't delete backup file"));
goto nofail;
--- 4985,4994 ----
}
}
! // Remove the backup unless 'backup' option is set or there was a
! // conversion error.
! if (!p_bk && backup != NULL && !write_info.bw_conv_error
! && mch_remove(backup) != 0)
emsg(_("E207: Can't delete backup file"));
goto nofail;
*** ../vim-8.1.1348/src/testdir/test_writefile.vim 2019-01-29
22:58:02.401136295 +0100
--- src/testdir/test_writefile.vim 2019-05-18 18:46:39.610661802 +0200
***************
*** 36,48 ****
if !has('iconv') || has('sun')
return
endif
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_equal(contents, readfile('Xfile'))
call delete('Xfile')
--- 36,50 ----
if !has('iconv') || has('sun')
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', 'E513:')
call assert_equal(contents, readfile('Xfile'))
call delete('Xfile')
***************
*** 50,55 ****
--- 52,78 ----
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
*** ../vim-8.1.1348/src/version.c 2019-05-18 17:22:51.016673960 +0200
--- src/version.c 2019-05-18 18:48:34.190060199 +0200
***************
*** 769,770 ****
--- 769,772 ----
{ /* Add new patch number below this line */
+ /**/
+ 1349,
/**/
--
Engineers are always delighted to share wisdom, even in areas in which they
have no experience whatsoever. Their logic provides them with inherent
insight into any field of expertise. This can be a problem when dealing with
the illogical people who believe that knowledge can only be derived through
experience.
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/201905181652.x4IGqKoD002216%40masaka.moolenaar.net.
For more options, visit https://groups.google.com/d/optout.