summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-05-06 17:09:38 +0200
committerBram Moolenaar <Bram@vim.org>2018-05-06 17:09:38 +0200
commit5aa9896b2e3330e32dc42a54731cc44ec904acca (patch)
tree86439bd11c592d1bb0066422e7d328b4c2f005d9 /src
parent6eddadff13164b98fe8198153cc656897b2cbcb3 (diff)
downloadvim-git-5aa9896b2e3330e32dc42a54731cc44ec904acca.tar.gz
patch 8.0.1798: MS-Windows: file considered read-only too oftenv8.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)
Diffstat (limited to 'src')
-rw-r--r--src/os_win32.c15
-rw-r--r--src/version.c2
2 files changed, 12 insertions, 5 deletions
diff --git a/src/os_win32.c b/src/os_win32.c
index a90dc1f79..602ef8aa2 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -6847,7 +6847,6 @@ default_shell(void)
mch_access(char *n, int p)
{
HANDLE hFile;
- DWORD am;
int retval = -1; /* default: fail */
#ifdef FEAT_MBYTE
WCHAR *wn = NULL;
@@ -6931,16 +6930,22 @@ mch_access(char *n, int p)
}
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. */
- am = ((p & W_OK) ? GENERIC_WRITE : 0)
- | ((p & R_OK) ? GENERIC_READ : 0);
+ DWORD access_mode = ((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);
+ hFile = CreateFileW(wn, access_mode, share_mode,
+ NULL, OPEN_EXISTING, 0, NULL);
else
#endif
- hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL);
+ hFile = CreateFile(n, access_mode, share_mode,
+ NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
goto getout;
CloseHandle(hFile);
diff --git a/src/version.c b/src/version.c
index 5fa69e3cd..0f0a1b7d2 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1798,
+/**/
1797,
/**/
1796,