fix(write): show E17 on all platforms #40595

Problems:
On Windows, `:w somedir` (where somedir is an existing directory
in pwd) shows the misleading `E13: File exists (add ! to override)`
instead of `E17: "somedir" is a directory`.

Solution:
drop unnecessary `#ifdef` guard.
This commit is contained in:
Willaaaaaaa
2026-07-20 03:42:59 +08:00
committed by GitHub
parent 7ba955fe07
commit 689b45dda3
2 changed files with 12 additions and 19 deletions

View File

@@ -2028,13 +2028,10 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, bool ot
&& !p_wa
&& os_path_exists(ffname)) {
if (!eap->forceit && !eap->append) {
#ifdef UNIX
// It is possible to open a directory on Unix.
if (os_isdir(ffname)) {
semsg(_(e_isadir2), ffname);
return FAIL;
}
#endif
if (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) {
char buff[DIALOG_MSG_SIZE];
snprintf(buff, sizeof buff, _("Overwrite existing file \"%s\"?"), fname);

View File

@@ -128,16 +128,14 @@ describe(':write', function()
)
eq('Vim(write):E32: No file name', pcall_err(command, 'write ++p Xotherdir/'))
if not is_os('win') then
eq(
('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'),
pcall_err(command, 'write ++p .')
)
eq(
('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'),
pcall_err(command, 'write ++p ./')
)
end
eq(
('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'),
pcall_err(command, 'write ++p .')
)
eq(
('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'),
pcall_err(command, 'write ++p ./')
)
t.matches(
'E474: Invalid argument',
@@ -149,12 +147,10 @@ describe(':write', function()
command('let $HOME=""')
eq(fn.fnamemodify('.', ':p:h'), fn.fnamemodify('.', ':p:h:~'))
-- Message from check_overwrite
if not is_os('win') then
eq(
('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'),
pcall_err(command, 'write .')
)
end
eq(
('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'),
pcall_err(command, 'write .')
)
api.nvim_set_option_value('writeany', true, {})
-- Message from buf_write
eq('Vim(write):E502: "." is a directory', pcall_err(command, 'write .'))