neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit bdf87efeb523aecffde7dbf3c17806f7ca98471f
parent b0190f4543397d6f3485e1eb03f30f80e358c201
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Mon,  7 Nov 2022 07:06:49 +0800

vim-patch:8.2.2856: get readonly error for device that can't be written to

Problem:    Get readonly error for device that can't be written to.
Solution:   Check for being able to write first. (closes vim/vim#8205)

https://github.com/vim/vim/commit/50157ef1c2e36d8696e79fd688bdd08312196bc6

Co-authored-by: Bram Moolenaar <Bram@vim.org>

Diffstat:
Msrc/nvim/ex_cmds.c | 17++++++++++++++++-
Msrc/nvim/testdir/test_writefile.vim | 2+-
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c @@ -1772,6 +1772,17 @@ void ex_write(exarg_T *eap) } } +#ifdef UNIX +static int check_writable(const char *fname) +{ + if (os_nodetype(fname) == NODE_OTHER) { + semsg(_("E503: \"%s\" is not a file or writable device"), fname); + return FAIL; + } + return OK; +} +#endif + /// write current buffer to file 'eap->arg' /// if 'eap->append' is true, append to the file /// @@ -1829,7 +1840,11 @@ int do_write(exarg_T *eap) // Writing to the current file is not allowed in readonly mode // and a file name is required. // "nofile" and "nowrite" buffers cannot be written implicitly either. - if (!other && (bt_dontwrite_msg(curbuf) || check_fname() == FAIL + if (!other && (bt_dontwrite_msg(curbuf) + || check_fname() == FAIL +#ifdef UNIX + || check_writable(curbuf->b_ffname) == FAIL +#endif || check_readonly(&eap->forceit, curbuf))) { goto theend; } diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim @@ -298,7 +298,7 @@ func Test_write_errors() \ && getftype('/dev/loop0') == 'bdev' && !IsRoot() new edit /dev/loop0 - call assert_fails('write', 'E505: ') + call assert_fails('write', 'E503: ') call assert_fails('write!', 'E503: ') close! endif