vim-patch:9.2.1005: backupcopy=auto overwrites a file in place with umask (#41502)

Problem:  backupcopy=auto overwrites a file in place when umask is restrictive.
          The probe treats permission restore as impossible and writes in
          place, keeping the same inode.
Solution: When creating the probe file, open() applies umask, so a 0644
          file becomes 0600 with umask 0077. Use fchmod() to fix the
          permissions of the probe (Pranav Dwivedi).

closes: vim/vim#21137

https://github.com/vim/vim/commit/fd8aea135d146915e921699cd23887b654182810

Co-authored-by: Pranav Dwivedi <dwivedipranav2021@gmail.com>
This commit is contained in:
zeertzjqandPranav Dwivedi authored and GitHub committed 2026-08-26 07:07:29 +00:00
1 parent f97bcbdf77
commit 0f0e89fd90
3 files changed
+32 -1

No files matched your search

+20
View File
@@ -1013,4 +1013,24 @@ func Test_write_with_xattr_support()
bw!
endfunc
func Test_backupcopy_auto_restrictive_umask()
CheckUnix
call writefile(['FOO'], 'Xumaskfile', 'D')
call setfperm('Xumaskfile', 'rw-r--r--')
let inode_before = systemlist('ls -i Xumaskfile')[0]->matchstr('^\s*\zs\d\+')
call writefile([
\ 'set backupcopy=auto writebackup nobackup backupskip=',
\ 'edit Xumaskfile',
\ 'call setline(1, ["BAR"])',
\ 'write',
\ 'qall!'
\ ], 'Xumaskscript', 'D')
call system('umask 0077; ' .. GetVimCommand() .. ' -i NONE -n -S Xumaskscript')
call assert_equal(0, v:shell_error)
call assert_equal(['BAR'], readfile('Xumaskfile'))
call assert_equal('rw-r--r--', getfperm('Xumaskfile'))
call assert_notequal(inode_before,
\ systemlist('ls -i Xumaskfile')[0]->matchstr('^\s*\zs\d\+'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab