summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-05-18 18:52:04 +0200
committerBram Moolenaar <Bram@vim.org>2019-05-18 18:52:04 +0200
commitcf0bfd9ade5173bcc12563bfc90c21a4db10535d (patch)
tree189907ca3e0ce6ca8d73adb3cc96ddd2cbb47275
parentf8191c5f07c650b75b85c5a5b3d000fd5cae1643 (diff)
downloadvim-git-cf0bfd9ade5173bcc12563bfc90c21a4db10535d.tar.gz
patch 8.1.1349: if writing runs into conversion error backup file is deletedv8.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)
-rw-r--r--src/fileio.c8
-rw-r--r--src/testdir/test_writefile.vim25
-rw-r--r--src/version.c2
3 files changed, 30 insertions, 5 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 659878eb9..4d9cd05f0 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4985,10 +4985,10 @@ restore_backup:
}
}
- /*
- * Remove the backup unless 'backup' option is set
- */
- if (!p_bk && backup != NULL && mch_remove(backup) != 0)
+ // 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;
diff --git a/src/testdir/test_writefile.vim b/src/testdir/test_writefile.vim
index ff3675661..a06333d80 100644
--- a/src/testdir/test_writefile.vim
+++ b/src/testdir/test_writefile.vim
@@ -36,13 +36,15 @@ func Test_writefile_fails_conversion()
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')
+ 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
diff --git a/src/version.c b/src/version.c
index a658c5ab0..efddd3eaf 100644
--- a/src/version.c
+++ b/src/version.c
@@ -768,6 +768,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1349,
+/**/
1348,
/**/
1347,