vim-patch:9.2.0673: tests: Test_recover_corrupted_swap_file() cannot handle symlinks

Problem:  tests: Test_recover_corrupted_swap_file() cannot handle
          symlinks
Solution: Use writefile(readblob()) instead (Vladimír Marek)

Test_recover_corrupted_swap_file1() copies prebuilt corrupt swap samples
before recovering them.  In an out-of-source-tree build those sample
files may be symlinks into the source tree.  filecopy() preserves
symlinks, so the copied target may remain a symlink.  Recovery opens
swap files with O_NOFOLLOW, so that copied symlink cannot be opened.
Read the sample as a blob and write it back so the recovery target is a
real swap file.

closes: vim/vim#20561

88cbd00312

Co-authored-by: Vladimír Marek <vlmarek13@gmail.com>
This commit is contained in:
zeertzjq
2026-06-19 09:39:45 +08:00
parent 025a3e2baf
commit 147872452e

View File

@@ -508,7 +508,9 @@ func Test_recover_corrupted_swap_file1()
new
let sample = 'samples/recover-crash1.swp'
let target = '.Xpoc1.swp' " Xpoc1.swp (non-hidden) doesn't work in Nvim
call filecopy(sample, target)
" In an out-of-source-tree build the sample may be a symlink, this copies the
" data into a real file.
call writefile(readblob(sample), target, 'D')
try
sil recover! Xpoc1
catch /^Vim\%((\S\+)\)\=:E1364:/
@@ -522,7 +524,9 @@ func Test_recover_corrupted_swap_file1()
new
let sample = 'samples/recover-crash2.swp'
let target = '.Xpoc2.swp' " Xpoc1.swp (non-hidden) doesn't work in Nvim
call filecopy(sample, target)
" In an out-of-source-tree build the sample may be a symlink, this copies the
" data into a real file.
call writefile(readblob(sample), target, 'D')
try
sil recover! Xpoc2
catch /^Vim\%((\S\+)\)\=:E1364:/