Mercurial > vim
comparison src/fileio.c @ 23017:d80faed40bec v8.2.2055
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Commit: https://github.com/vim/vim/commit/2472a74be4dedfeaff22314f31cf9787618163d1
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 26 19:47:28 2020 +0100
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Problem: MS-Windows: two Vim instances may use the same temp file.
Solution: Use the process ID for the temp name. (Ken Takata, closes https://github.com/vim/vim/issues/7378)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 26 Nov 2020 20:00:06 +0100 |
parents | f7f2d73ff85e |
children | 826a6406ea7b |
comparison
equal
deleted
inserted
replaced
23016:7f40dcbf9222 | 23017:d80faed40bec |
---|---|
5165 #else // TEMPDIRNAMES | 5165 #else // TEMPDIRNAMES |
5166 | 5166 |
5167 # ifdef MSWIN | 5167 # ifdef MSWIN |
5168 WCHAR wszTempFile[_MAX_PATH + 1]; | 5168 WCHAR wszTempFile[_MAX_PATH + 1]; |
5169 WCHAR buf4[4]; | 5169 WCHAR buf4[4]; |
5170 WCHAR *chartab = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
5170 char_u *retval; | 5171 char_u *retval; |
5171 char_u *p; | 5172 char_u *p; |
5173 long i; | |
5172 | 5174 |
5173 wcscpy(itmp, L""); | 5175 wcscpy(itmp, L""); |
5174 if (GetTempPathW(_MAX_PATH, wszTempFile) == 0) | 5176 if (GetTempPathW(_MAX_PATH, wszTempFile) == 0) |
5175 { | 5177 { |
5176 wszTempFile[0] = L'.'; // GetTempPathW() failed, use current dir | 5178 wszTempFile[0] = L'.'; // GetTempPathW() failed, use current dir |
5177 wszTempFile[1] = NUL; | 5179 wszTempFile[1] = L'\\'; |
5180 wszTempFile[2] = NUL; | |
5178 } | 5181 } |
5179 wcscpy(buf4, L"VIM"); | 5182 wcscpy(buf4, L"VIM"); |
5180 buf4[2] = extra_char; // make it "VIa", "VIb", etc. | 5183 |
5184 // randomize the name to avoid collisions | |
5185 i = mch_get_pid() + extra_char; | |
5186 buf4[1] = chartab[i % 36]; | |
5187 buf4[2] = chartab[101 * i % 36]; | |
5181 if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0) | 5188 if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0) |
5182 return NULL; | 5189 return NULL; |
5183 if (!keep) | 5190 if (!keep) |
5184 // GetTempFileName() will create the file, we don't want that | 5191 // GetTempFileName() will create the file, we don't want that |
5185 (void)DeleteFileW(itmp); | 5192 (void)DeleteFileW(itmp); |