diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-11-09 21:04:17 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-11-09 21:04:17 +0100 |
commit | f883508e36c209d60388b944e04e22a3fcf603cf (patch) | |
tree | 38bcbc7e7626d1e5178a57cf48ca9ce12837d687 /src/memline.c | |
parent | ea696852e7abcdebaf7f17a7f23dc90df1f5e2ed (diff) | |
download | vim-git-f883508e36c209d60388b944e04e22a3fcf603cf.tar.gz |
patch 8.2.1970: it is easy to make mistakes when cleaning up swap filesv8.2.1970
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)
Diffstat (limited to 'src/memline.c')
-rw-r--r-- | src/memline.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/memline.c b/src/memline.c index e0a49cb7e..bf6a18499 100644 --- a/src/memline.c +++ b/src/memline.c @@ -1690,7 +1690,17 @@ ml_recover(int checkext) } else msg(_("Recovery completed. Buffer contents equals file contents.")); - msg_puts(_("\nYou may want to delete the .swp file now.\n\n")); + msg_puts(_("\nYou may want to delete the .swp file now.")); +#if defined(UNIX) || defined(MSWIN) + if (mch_process_running(char_to_long(b0p->b0_pid))) + { + // Warn there could be an active Vim on the same file, the user may + // want to kill it. + msg_puts(_("\nNote: process STILL RUNNING: ")); + msg_outnum(char_to_long(b0p->b0_pid)); + } +#endif + msg_puts("\n\n"); cmdline_row = msg_row; } #ifdef FEAT_CRYPT @@ -2230,14 +2240,30 @@ swapfile_unchanged(char_u *fname) ret = FALSE; #if defined(UNIX) || defined(MSWIN) + // Host name must be known and must equal the current host name, otherwise + // comparing pid is meaningless. + if (*(b0.b0_hname) == NUL) + { + ret = FALSE; + } + else + { + char_u hostname[B0_HNAME_SIZE]; + + mch_get_host_name(hostname, B0_HNAME_SIZE); + hostname[B0_HNAME_SIZE - 1] = NUL; + if (STRICMP(b0.b0_hname, hostname) != 0) + ret = FALSE; + } + // process must be known and not be running pid = char_to_long(b0.b0_pid); if (pid == 0L || mch_process_running(pid)) ret = FALSE; #endif - // TODO: Should we check if the swap file was created on the current - // system? And the current user? + // We do not check the user, it should be irrelevant for whether the swap + // file is still useful. close(fd); return ret; |