mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.2960: swap file recovery not sufficiently tested
Problem: Swap file recovery not sufficiently tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes #8339)
This commit is contained in:
parent
2f9c209ba0
commit
8cf02e5cf8
@ -146,6 +146,16 @@ func Test_recover_multiple_swap_files()
|
||||
%bw!
|
||||
call feedkeys(":recover Xfile1\<CR>3\<CR>q", 'xt')
|
||||
call assert_equal(['a', 'b', 'c'], getline(1, '$'))
|
||||
" try using out-of-range number to select a swap file
|
||||
bw!
|
||||
call feedkeys(":recover Xfile1\<CR>4\<CR>q", 'xt')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal([''], getline(1, '$'))
|
||||
bw!
|
||||
call feedkeys(":recover Xfile1\<CR>0\<CR>q", 'xt')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal([''], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
call delete('.Xfile1.swm')
|
||||
call delete('.Xfile1.swn')
|
||||
@ -166,6 +176,8 @@ func Test_recover_empty_swap_file()
|
||||
endfunc
|
||||
|
||||
" Test for :recover using a corrupted swap file
|
||||
" Refer to the comments in the memline.c file for the swap file headers
|
||||
" definition.
|
||||
func Test_recover_corrupted_swap_file()
|
||||
CheckUnix
|
||||
|
||||
@ -197,6 +209,18 @@ func Test_recover_corrupted_swap_file()
|
||||
call writefile(b, sn)
|
||||
let msg = execute('recover Xfile1')
|
||||
call assert_match('the file has been damaged', msg)
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal([''], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
" reduce the page size
|
||||
let b = copy(save_b)
|
||||
let b[12:15] = 0z00010000
|
||||
call writefile(b, sn)
|
||||
let msg = execute('recover Xfile1')
|
||||
call assert_match('page size is smaller than minimum value', msg)
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal([''], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
" clear the pointer ID
|
||||
@ -204,6 +228,26 @@ func Test_recover_corrupted_swap_file()
|
||||
let b[4096:4097] = 0z0000
|
||||
call writefile(b, sn)
|
||||
call assert_fails('recover Xfile1', 'E310:')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal([''], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
" set the number of pointers in a pointer block to zero
|
||||
let b = copy(save_b)
|
||||
let b[4098:4099] = 0z0000
|
||||
call writefile(b, sn)
|
||||
call assert_fails('recover Xfile1', 'E312:')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal(['???EMPTY BLOCK'], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
" set the block number in a pointer entry to a negative number
|
||||
let b = copy(save_b)
|
||||
let b[4104:4111] = 0z00000000.00000080
|
||||
call writefile(b, sn)
|
||||
call assert_fails('recover Xfile1', 'E312:')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal(['???LINES MISSING'], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
" clear the data block ID
|
||||
@ -211,12 +255,45 @@ func Test_recover_corrupted_swap_file()
|
||||
let b[8192:8193] = 0z0000
|
||||
call writefile(b, sn)
|
||||
call assert_fails('recover Xfile1', 'E312:')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal(['???BLOCK MISSING'], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
" set the number of lines in the data block to zero
|
||||
let b = copy(save_b)
|
||||
let b[8208:8211] = 0z00000000
|
||||
call writefile(b, sn)
|
||||
call assert_fails('recover Xfile1', 'E312:')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal(['??? from here until ???END lines may have been inserted/deleted',
|
||||
\ '???END'], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
" use an invalid text start for the lines in a data block
|
||||
let b = copy(save_b)
|
||||
let b[8216:8219] = 0z00000000
|
||||
call writefile(b, sn)
|
||||
call assert_fails('recover Xfile1', 'E312:')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal(['???'], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
" use an incorrect text end (db_txt_end) for the data block
|
||||
let b = copy(save_b)
|
||||
let b[8204:8207] = 0z80000000
|
||||
call writefile(b, sn)
|
||||
call assert_fails('recover Xfile1', 'E312:')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal(['??? from here until ???END lines may be messed up', '',
|
||||
\ '???END'], getline(1, '$'))
|
||||
bw!
|
||||
|
||||
" remove the data block
|
||||
let b = copy(save_b)
|
||||
call writefile(b[:8191], sn)
|
||||
call assert_fails('recover Xfile1', 'E312:')
|
||||
call assert_equal('Xfile1', @%)
|
||||
call assert_equal(['???MANY LINES MISSING'], getline(1, '$'))
|
||||
endif
|
||||
|
||||
bw!
|
||||
@ -290,4 +367,27 @@ func Test_recover_unmodified_file()
|
||||
call delete('.Xfile1.swz')
|
||||
endfunc
|
||||
|
||||
" Test for recovering a file when editing a symbolically linked file
|
||||
func Test_recover_symbolic_link()
|
||||
CheckUnix
|
||||
call writefile(['aaa', 'bbb', 'ccc'], 'Xfile1')
|
||||
silent !ln -s Xfile1 Xfile2
|
||||
edit Xfile2
|
||||
call assert_equal('.Xfile1.swp', fnamemodify(swapname(''), ':t'))
|
||||
preserve
|
||||
let b = readblob('.Xfile1.swp')
|
||||
%bw!
|
||||
call writefile([], 'Xfile1')
|
||||
call writefile(b, '.Xfile1.swp')
|
||||
silent! recover Xfile2
|
||||
call assert_equal(['aaa', 'bbb', 'ccc'], getline(1, '$'))
|
||||
call assert_true(&modified)
|
||||
update
|
||||
%bw!
|
||||
call assert_equal(['aaa', 'bbb', 'ccc'], readfile('Xfile1'))
|
||||
call delete('Xfile1')
|
||||
call delete('Xfile2')
|
||||
call delete('.Xfile1.swp')
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
2960,
|
||||
/**/
|
||||
2959,
|
||||
/**/
|
||||
|
Loading…
x
Reference in New Issue
Block a user