From ce0fddf5ae334f0c79dcd95b379999e11df1486b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 9 Mar 2023 08:07:36 -0500 Subject: feat: try to recover from missing tempdir #22573 Problem: If vim_tempdir mysteriously goes missing (typically by "antivirus" on Windows), any plugins using tempname() will be broken for the rest of the session. #1432 #9833 https://groups.google.com/g/vim_use/c/ef55jNm5czI Steps: mkdir foo TMPDIR=./foo nvim :echo tempname() !rm -r foo :echo tempname() tempname() still uses the foo path even though it was deleted. Solution: - Don't assume that vim_tempdir exists. - If it goes missing once, retry vim_mktempdir and log (silently) an error. - If it goes missing again, retry vim_mktempdir and show an error. Rejected in Vim for performance reasons: https://groups.google.com/g/vim_use/c/qgRob9SWDv8/m/FAOFVVcDTv0J https://groups.google.com/g/vim_dev/c/cogp-Vye4oo/m/d_SVFXBbnnoJ But, logging shows that `vim_gettempdir` is not called frequently. Fixes #1432 Fixes #9833 Fixes #11250 Related: stdpath("run") f50135a32e11c535e1dc3a8e9460c5b4e640ee86 --- src/nvim/fileio.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 6a13548027..115d34c3ea 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -5369,10 +5369,21 @@ void vim_deltempdir(void) /// Creates the directory on the first call. char *vim_gettempdir(void) { - if (vim_tempdir == NULL) { + static int notfound = 0; + bool exists = false; + if (vim_tempdir == NULL || !(exists = os_isdir(vim_tempdir))) { + if (vim_tempdir != NULL && !exists) { + notfound++; + if (notfound == 1) { + ELOG("tempdir disappeared (antivirus or broken cleanup job?): %s", vim_tempdir); + } + if (notfound > 1) { + msg_schedule_semsg("E5431: tempdir disappeared (%d times)", notfound); + } + XFREE_CLEAR(vim_tempdir); + } vim_mktempdir(); } - return vim_tempdir; } -- cgit