Mercurial > vim
comparison src/memline.c @ 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 | e82579016863 |
children | 4cce4a5d3fd3 |
comparison
equal
deleted
inserted
replaced
22845:f71f0cf1841b | 22846:83c2c489cb1b |
---|---|
1688 msg_puts(_("\n(You might want to write out this file under another name\n")); | 1688 msg_puts(_("\n(You might want to write out this file under another name\n")); |
1689 msg_puts(_("and run diff with the original file to check for changes)")); | 1689 msg_puts(_("and run diff with the original file to check for changes)")); |
1690 } | 1690 } |
1691 else | 1691 else |
1692 msg(_("Recovery completed. Buffer contents equals file contents.")); | 1692 msg(_("Recovery completed. Buffer contents equals file contents.")); |
1693 msg_puts(_("\nYou may want to delete the .swp file now.\n\n")); | 1693 msg_puts(_("\nYou may want to delete the .swp file now.")); |
1694 #if defined(UNIX) || defined(MSWIN) | |
1695 if (mch_process_running(char_to_long(b0p->b0_pid))) | |
1696 { | |
1697 // Warn there could be an active Vim on the same file, the user may | |
1698 // want to kill it. | |
1699 msg_puts(_("\nNote: process STILL RUNNING: ")); | |
1700 msg_outnum(char_to_long(b0p->b0_pid)); | |
1701 } | |
1702 #endif | |
1703 msg_puts("\n\n"); | |
1694 cmdline_row = msg_row; | 1704 cmdline_row = msg_row; |
1695 } | 1705 } |
1696 #ifdef FEAT_CRYPT | 1706 #ifdef FEAT_CRYPT |
1697 if (*buf->b_p_key != NUL && STRCMP(curbuf->b_p_key, buf->b_p_key) != 0) | 1707 if (*buf->b_p_key != NUL && STRCMP(curbuf->b_p_key, buf->b_p_key) != 0) |
1698 { | 1708 { |
2228 // must be unchanged | 2238 // must be unchanged |
2229 if (b0.b0_dirty) | 2239 if (b0.b0_dirty) |
2230 ret = FALSE; | 2240 ret = FALSE; |
2231 | 2241 |
2232 #if defined(UNIX) || defined(MSWIN) | 2242 #if defined(UNIX) || defined(MSWIN) |
2243 // Host name must be known and must equal the current host name, otherwise | |
2244 // comparing pid is meaningless. | |
2245 if (*(b0.b0_hname) == NUL) | |
2246 { | |
2247 ret = FALSE; | |
2248 } | |
2249 else | |
2250 { | |
2251 char_u hostname[B0_HNAME_SIZE]; | |
2252 | |
2253 mch_get_host_name(hostname, B0_HNAME_SIZE); | |
2254 hostname[B0_HNAME_SIZE - 1] = NUL; | |
2255 if (STRICMP(b0.b0_hname, hostname) != 0) | |
2256 ret = FALSE; | |
2257 } | |
2258 | |
2233 // process must be known and not be running | 2259 // process must be known and not be running |
2234 pid = char_to_long(b0.b0_pid); | 2260 pid = char_to_long(b0.b0_pid); |
2235 if (pid == 0L || mch_process_running(pid)) | 2261 if (pid == 0L || mch_process_running(pid)) |
2236 ret = FALSE; | 2262 ret = FALSE; |
2237 #endif | 2263 #endif |
2238 | 2264 |
2239 // TODO: Should we check if the swap file was created on the current | 2265 // We do not check the user, it should be irrelevant for whether the swap |
2240 // system? And the current user? | 2266 // file is still useful. |
2241 | 2267 |
2242 close(fd); | 2268 close(fd); |
2243 return ret; | 2269 return ret; |
2244 } | 2270 } |
2245 | 2271 |