From 883cb92bc5e276bae187391f5d6f863a90eced4c Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 8 Jan 2017 01:24:38 +0100 Subject: [PATCH] Prevent more FILE_SHARE_VIOLATIONS for deleting files Relates to issue #497, however, does not fix it as sometimes also pack files are locked. Signed-off-by: Sven Strickroth --- ...eFile-with-FILE_SHARE_DELETE-for-O_RDONLY.patch | 42 ++++++++++++++++++++++ src/Changelog.txt | 1 + 2 files changed, 43 insertions(+) create mode 100644 ext/libgit2-0006-Use-CreateFile-with-FILE_SHARE_DELETE-for-O_RDONLY.patch diff --git a/ext/libgit2-0006-Use-CreateFile-with-FILE_SHARE_DELETE-for-O_RDONLY.patch b/ext/libgit2-0006-Use-CreateFile-with-FILE_SHARE_DELETE-for-O_RDONLY.patch new file mode 100644 index 000000000..f534fa861 --- /dev/null +++ b/ext/libgit2-0006-Use-CreateFile-with-FILE_SHARE_DELETE-for-O_RDONLY.patch @@ -0,0 +1,42 @@ +From 57dce6dd6fb6b1279dd73d14962ab04612cf316f Mon Sep 17 00:00:00 2001 +From: Sven Strickroth +Date: Sun, 8 Jan 2017 01:18:08 +0100 +Subject: [PATCH] Use CreateFile with FILE_SHARE_DELETE for O_RDONLY + +This prevents FILE_SHARED_VIOLATIONS when used in tools such as +TortoiseGit TGitCache, because the file is not locked. + +Signed-off-by: Sven Strickroth +--- + src/win32/posix_w32.c | 15 +++++++++++++++ + 1 file changed, 15 insertions(+) + +diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c +index fea634b00..9839b24cf 100644 +--- a/src/win32/posix_w32.c ++++ b/src/win32/posix_w32.c +@@ -295,6 +295,21 @@ int p_open(const char *path, int flags, ...) + mode = (mode_t)va_arg(arg_list, int); + va_end(arg_list); + } ++ else if (flags == O_RDONLY) { ++ // use CreateFile here, so that we can request FILE_SHARE_DELETE ++ HANDLE handle; ++ ++ SECURITY_ATTRIBUTES security_attributes; ++ security_attributes.nLength = sizeof(security_attributes); ++ security_attributes.lpSecurityDescriptor = NULL; ++ security_attributes.bInheritHandle = FALSE; ++ ++ handle = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, &security_attributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); ++ if (handle == INVALID_HANDLE_VALUE) ++ return -1; ++ ++ return _open_osfhandle((intptr_t)handle, 0); ++ } + + return _wopen(buf, flags | STANDARD_OPEN_FLAGS, mode & WIN32_MODE_MASK); + } +-- +2.11.0.windows.1 + diff --git a/src/Changelog.txt b/src/Changelog.txt index a9c3cc831..8daaf6c4b 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -73,6 +73,7 @@ Released: unreleased * Fixed issue #2883: Improve wording for our "needs merge" hint in commit dialog * Fixed issue #2898: Branch name forced to be lower what leads to pull error * TGitCache: Do not accidentally report up status of submodules to parent repo if not enabled + * TGitCache: Prevent more FILE_SHARE_VIOLATIONS for deleting files = Release 2.3.0 = Released: 2016-10-01 -- 2.11.4.GIT