Mercurial > vim
comparison src/os_win32.c @ 13853:1ea18443d569 v8.0.1798
patch 8.0.1798: MS-Windows: file considered read-only too often
commit https://github.com/vim/vim/commit/5aa9896b2e3330e32dc42a54731cc44ec904acca
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 6 17:09:38 2018 +0200
patch 8.0.1798: MS-Windows: file considered read-only too often
Problem: MS-Windows: file considered read-only when another program has
opened it.
Solution: Pass file sharing flag to CreateFile(). (Linwei, closes #2860)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 06 May 2018 17:15:05 +0200 |
parents | ca8953d36264 |
children | f39150ec146e |
comparison
equal
deleted
inserted
replaced
13852:50956a238b39 | 13853:1ea18443d569 |
---|---|
6845 */ | 6845 */ |
6846 int | 6846 int |
6847 mch_access(char *n, int p) | 6847 mch_access(char *n, int p) |
6848 { | 6848 { |
6849 HANDLE hFile; | 6849 HANDLE hFile; |
6850 DWORD am; | |
6851 int retval = -1; /* default: fail */ | 6850 int retval = -1; /* default: fail */ |
6852 #ifdef FEAT_MBYTE | 6851 #ifdef FEAT_MBYTE |
6853 WCHAR *wn = NULL; | 6852 WCHAR *wn = NULL; |
6854 | 6853 |
6855 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) | 6854 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
6929 } | 6928 } |
6930 } | 6929 } |
6931 } | 6930 } |
6932 else | 6931 else |
6933 { | 6932 { |
6933 // Don't consider a file read-only if another process has opened it. | |
6934 DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; | |
6935 | |
6934 /* Trying to open the file for the required access does ACL, read-only | 6936 /* Trying to open the file for the required access does ACL, read-only |
6935 * network share, and file attribute checks. */ | 6937 * network share, and file attribute checks. */ |
6936 am = ((p & W_OK) ? GENERIC_WRITE : 0) | 6938 DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0) |
6937 | ((p & R_OK) ? GENERIC_READ : 0); | 6939 | ((p & R_OK) ? GENERIC_READ : 0); |
6940 | |
6938 #ifdef FEAT_MBYTE | 6941 #ifdef FEAT_MBYTE |
6939 if (wn != NULL) | 6942 if (wn != NULL) |
6940 hFile = CreateFileW(wn, am, 0, NULL, OPEN_EXISTING, 0, NULL); | 6943 hFile = CreateFileW(wn, access_mode, share_mode, |
6944 NULL, OPEN_EXISTING, 0, NULL); | |
6941 else | 6945 else |
6942 #endif | 6946 #endif |
6943 hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL); | 6947 hFile = CreateFile(n, access_mode, share_mode, |
6948 NULL, OPEN_EXISTING, 0, NULL); | |
6944 if (hFile == INVALID_HANDLE_VALUE) | 6949 if (hFile == INVALID_HANDLE_VALUE) |
6945 goto getout; | 6950 goto getout; |
6946 CloseHandle(hFile); | 6951 CloseHandle(hFile); |
6947 } | 6952 } |
6948 | 6953 |