From dfe55e2b924b86c654b63edb9bedc42aa4e08048 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Wed, 25 Nov 2020 12:42:00 +0000 Subject: [PATCH] Recreate temp directory if it gets deleted Vim does not check the existence of its temp directory when generating file names with tempname(). Therefore if, for some reason, the temp directory gets deleted, Vim will continue to generate paths for file names inside the directory. Writes to these file paths will fail (E482). See #746, #433, #190, #147. --- autoload/gitgutter/diff.vim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index 22c26db..d88f8f0 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -399,7 +399,16 @@ function! s:write_buffer(bufnr, file) let bufcontents[0]=''.bufcontents[0] endif - call writefile(bufcontents, a:file, 'b') + " The file we are writing to is a temporary file. Sometimes the parent + " directory is deleted outside Vim but, because Vim caches the directory + " name at startup and does not check for its existence subsequently, Vim + " does not realise. This causes E482 errors. + try + call writefile(bufcontents, a:file, 'b') + catch /E482/ + call mkdir(fnamemodify(a:file, ':h'), '', '0700') + call writefile(bufcontents, a:file, 'b') + endtry endfunction