]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0332: overwrite check may block BufWriteCmd v9.0.0332
authorzeertzjq <zeertzjq@outlook.com>
Tue, 30 Aug 2022 17:17:15 +0000 (18:17 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 30 Aug 2022 17:17:15 +0000 (18:17 +0100)
Problem:    Overwrite check may block BufWriteCmd.
Solution:   Do not use overwrite check when 'buftype' is "acwrite".
            (closes #11011)

src/ex_cmds.c
src/testdir/test_autocmd.vim
src/version.c

index d9f1c993db9e86fc45342ce76676f3e59fc6963e..1cf090cd811bb522e6c43c702ef55b98de26e7f2 100644 (file)
@@ -2094,12 +2094,17 @@ check_overwrite(
     /*
      * Write to another file or b_flags set or not writing the whole file:
      * overwriting only allowed with '!'.
+     * If "other" is FALSE and bt_nofilename(buf) is TRUE, this must be
+     * writing an "acwrite" buffer to the same file as its b_ffname, and
+     * buf_write() will only allow writing with BufWriteCmd autocommands,
+     * so there is no need for an overwrite check.
      */
     if (       (other
-               || (buf->b_flags & BF_NOTEDITED)
-               || ((buf->b_flags & BF_NEW)
-                   && vim_strchr(p_cpo, CPO_OVERNEW) == NULL)
-               || (buf->b_flags & BF_READERR))
+               || (!bt_nofilename(buf)
+                   && ((buf->b_flags & BF_NOTEDITED)
+                       || ((buf->b_flags & BF_NEW)
+                           && vim_strchr(p_cpo, CPO_OVERNEW) == NULL)
+                       || (buf->b_flags & BF_READERR))))
            && !p_wa
            && vim_fexists(ffname))
     {
index e4b76dba57c09ceb112d9f9eeaadd0a060d87f0d..b3b4ec5a6fcf1ff0c6f283f253974c46dd3f8d0a 100644 (file)
@@ -1922,6 +1922,21 @@ func Test_BufReadCmd()
   au! BufWriteCmd
 endfunc
 
+func Test_BufWriteCmd()
+  autocmd BufWriteCmd Xbufwritecmd let g:written = 1
+  new
+  file Xbufwritecmd
+  set buftype=acwrite
+  call mkdir('Xbufwritecmd')
+  write
+  " BufWriteCmd should be triggered even if a directory has the same name
+  call assert_equal(1, g:written)
+  call delete('Xbufwritecmd', 'd')
+  unlet g:written
+  au! BufWriteCmd
+  bwipe!
+endfunc
+
 func SetChangeMarks(start, end)
   exe a:start .. 'mark ['
   exe a:end .. 'mark ]'
index 2f409cf5a4ef1c55170f2e1be821b8bb8dd4663f..68d0e791a7d3f65b805380f15ffc7760a018d1a0 100644 (file)
@@ -707,6 +707,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    332,
 /**/
     331,
 /**/