To: vim_dev@googlegroups.com Subject: Patch 8.0.1798 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1798 Problem: MS-Windows: file considered read-only when another program has opened it. Solution: Pass file sharing flag to CreateFile(). (Linwei, closes #2860) Files: src/os_win32.c *** ../vim-8.0.1797/src/os_win32.c 2018-05-05 14:29:02.425738226 +0200 --- src/os_win32.c 2018-05-06 17:05:39.425707385 +0200 *************** *** 6847,6853 **** mch_access(char *n, int p) { HANDLE hFile; - DWORD am; int retval = -1; /* default: fail */ #ifdef FEAT_MBYTE WCHAR *wn = NULL; --- 6847,6852 ---- *************** *** 6931,6946 **** } else { /* Trying to open the file for the required access does ACL, read-only * network share, and file attribute checks. */ ! am = ((p & W_OK) ? GENERIC_WRITE : 0) ! | ((p & R_OK) ? GENERIC_READ : 0); #ifdef FEAT_MBYTE if (wn != NULL) ! hFile = CreateFileW(wn, am, 0, NULL, OPEN_EXISTING, 0, NULL); else #endif ! hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) goto getout; CloseHandle(hFile); --- 6930,6951 ---- } else { + // Don't consider a file read-only if another process has opened it. + DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; + /* Trying to open the file for the required access does ACL, read-only * network share, and file attribute checks. */ ! DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0) ! | ((p & R_OK) ? GENERIC_READ : 0); ! #ifdef FEAT_MBYTE if (wn != NULL) ! hFile = CreateFileW(wn, access_mode, share_mode, ! NULL, OPEN_EXISTING, 0, NULL); else #endif ! hFile = CreateFile(n, access_mode, share_mode, ! NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) goto getout; CloseHandle(hFile); *** ../vim-8.0.1797/src/version.c 2018-05-06 16:40:12.239619606 +0200 --- src/version.c 2018-05-06 17:07:47.445003215 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1798, /**/ -- Courtroom Quote #19: Q: Doctor, how many autopsies have you performed on dead people? A: All my autopsies have been performed on dead people. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///