diff options
| author | Sven Strickroth <email@cs-ware.de> | 2017-01-14 18:39:32 +0100 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2017-04-03 23:13:00 +0100 |
| commit | d5e6ca1e4a3f21ef9eb94c9e74cc4afb77194751 (patch) | |
| tree | 4b9667e649644089c5107d957603da6e4e2b9bb7 /src | |
| parent | 92d5a6377ad4d77bc51bb596ff7c78e9bcd0f902 (diff) | |
| download | libgit2-d5e6ca1e4a3f21ef9eb94c9e74cc4afb77194751.tar.gz | |
Allow to configure default file share mode for opening files
This can prevent FILE_SHARED_VIOLATIONS when used in tools such as TortoiseGit TGitCache and FILE_SHARE_DELETE, because files can be opened w/o being locked any more.
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Diffstat (limited to 'src')
| -rw-r--r-- | src/settings.c | 12 | ||||
| -rw-r--r-- | src/win32/posix.h | 2 | ||||
| -rw-r--r-- | src/win32/posix_w32.c | 17 |
3 files changed, 20 insertions, 11 deletions
diff --git a/src/settings.c b/src/settings.c index 24e549ec1..07ac16a8f 100644 --- a/src/settings.c +++ b/src/settings.c @@ -231,6 +231,18 @@ int git_libgit2_opts(int key, ...) git_object__synchronous_writing = (va_arg(ap, int) != 0); break; + case GIT_OPT_GET_WINDOWS_SHAREMODE: +#ifdef GIT_WIN32 + *(va_arg(ap, unsigned long *)) = git_win32__createfile_sharemode; +#endif + break; + + case GIT_OPT_SET_WINDOWS_SHAREMODE: +#ifdef GIT_WIN32 + git_win32__createfile_sharemode = va_arg(ap, unsigned long); +#endif + break; + default: giterr_set(GITERR_INVALID, "invalid option key"); error = -1; diff --git a/src/win32/posix.h b/src/win32/posix.h index 73705fb2b..0ba05a16f 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -14,6 +14,8 @@ #include "utf-conv.h" #include "dir.h" +extern unsigned long git_win32__createfile_sharemode; + typedef SOCKET GIT_SOCKET; #define p_lseek(f,n,w) _lseeki64(f, n, w) diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index 28cd3e2e9..4943ce202 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -26,15 +26,6 @@ #define IO_REPARSE_TAG_SYMLINK (0xA000000CL) #endif -/* Options which we always provide to _wopen. - * - * _O_BINARY - Raw access; no translation of CR or LF characters - * _O_NOINHERIT - Do not mark the created handle as inheritable by child processes. - * The Windows default is 'not inheritable', but the CRT's default (following - * POSIX convention) is 'inheritable'. We have no desire for our handles to be - * inheritable on Windows, so specify the flag to get default behavior back. */ -#define STANDARD_OPEN_FLAGS (_O_BINARY | _O_NOINHERIT) - /* Allowable mode bits on Win32. Using mode bits that are not supported on * Win32 (eg S_IRWXU) is generally ignored, but Wine warns loudly about it * so we simply remove them. @@ -44,6 +35,9 @@ /* GetFinalPathNameByHandleW signature */ typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD); +unsigned long git_win32__createfile_sharemode = + FILE_SHARE_READ | FILE_SHARE_WRITE; + GIT_INLINE(void) set_errno(void) { switch (GetLastError()) { @@ -489,7 +483,7 @@ int p_open(const char *path, int flags, ...) break; } - sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; + sharing = (DWORD)git_win32__createfile_sharemode; switch (flags & (O_CREAT | O_TRUNC | O_EXCL)) { case O_CREAT | O_EXCL: @@ -510,7 +504,8 @@ int p_open(const char *path, int flags, ...) break; } - attributes = (mode & S_IWRITE) ? FILE_ATTRIBUTE_NORMAL : FILE_ATTRIBUTE_READONLY; + attributes = ((flags & O_CREAT) && !(mode & S_IWRITE)) ? + FILE_ATTRIBUTE_READONLY : FILE_ATTRIBUTE_NORMAL; osf_flags = flags & (O_RDONLY | O_APPEND); do_with_retries( |
