mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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)
50157ef1c2
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
b0190f4543
commit
bdf87efeb5
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user