Mercurial > vim
comparison src/testdir/test_swap.vim @ 22846:83c2c489cb1b v8.2.1970
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Commit: https://github.com/vim/vim/commit/f883508e36c209d60388b944e04e22a3fcf603cf
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Nov 9 21:04:17 2020 +0100
patch 8.2.1970: it is easy to make mistakes when cleaning up swap files
Problem: It is easy to make mistakes when cleaning up swap files after the
system crashed.
Solution: Warn for the process still running after recovery. Do not
automatically delete a swap file created on another system.
(David Fries, closes #7273)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 09 Nov 2020 21:15:03 +0100 |
parents | 08940efa6b4e |
children | 760526e5cd29 |
comparison
equal
deleted
inserted
replaced
22845:f71f0cf1841b | 22846:83c2c489cb1b |
---|---|
401 call delete('Xtestfile') | 401 call delete('Xtestfile') |
402 call delete('Xtestlink') | 402 call delete('Xtestlink') |
403 call delete('Xswapdir', 'rf') | 403 call delete('Xswapdir', 'rf') |
404 endfunc | 404 endfunc |
405 | 405 |
406 func Test_swap_auto_delete() | |
407 " Create a valid swapfile by editing a file with a special extension. | |
408 split Xtest.scr | |
409 call setline(1, ['one', 'two', 'three']) | |
410 write " file is written, not modified | |
411 write " write again to make sure the swapfile is created | |
412 " read the swapfile as a Blob | |
413 let swapfile_name = swapname('%') | |
414 let swapfile_bytes = readfile(swapfile_name, 'B') | |
415 | |
416 " Forget about the file, recreate the swap file, then edit it again. The | |
417 " swap file should be automatically deleted. | |
418 bwipe! | |
419 " change the process ID to avoid the "still running" warning | |
420 let swapfile_bytes[24] = 0x99 | |
421 call writefile(swapfile_bytes, swapfile_name) | |
422 edit Xtest.scr | |
423 " will end up using the same swap file after deleting the existing one | |
424 call assert_equal(swapfile_name, swapname('%')) | |
425 bwipe! | |
426 | |
427 " create the swap file again, but change the host name so that it won't be | |
428 " deleted | |
429 autocmd! SwapExists | |
430 augroup test_swap_recover_ext | |
431 autocmd! | |
432 autocmd SwapExists * let v:swapchoice = 'e' | |
433 augroup END | |
434 | |
435 " change the host name | |
436 let swapfile_bytes[28 + 40] = 0x89 | |
437 call writefile(swapfile_bytes, swapfile_name) | |
438 edit Xtest.scr | |
439 call assert_equal(1, filereadable(swapfile_name)) | |
440 " will use another same swap file name | |
441 call assert_notequal(swapfile_name, swapname('%')) | |
442 bwipe! | |
443 | |
444 call delete('Xtest.scr') | |
445 call delete(swapfile_name) | |
446 augroup test_swap_recover_ext | |
447 autocmd! | |
448 augroup END | |
449 augroup! test_swap_recover_ext | |
450 endfunc | |
451 | |
406 " vim: shiftwidth=2 sts=2 expandtab | 452 " vim: shiftwidth=2 sts=2 expandtab |