From 689b45dda32d3cdb1827ed3c3e50d66bfb02a627 Mon Sep 17 00:00:00 2001 From: Willaaaaaaa Date: Mon, 20 Jul 2026 03:42:59 +0800 Subject: [PATCH] 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. --- src/nvim/ex_cmds.c | 3 --- test/functional/ex_cmds/write_spec.lua | 28 +++++++++++--------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a7b8d1a39c..10f68c2c45 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -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); diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index e42f46bcaa..003a191f68 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -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 .'))