From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 2/4] mingw: implement lock_or_unlock_fd_for_appending()
Date: Thu, 09 Aug 2018 10:35:27 -0700 (PDT) [thread overview]
Message-ID: <8dda2d5303952306520bc90c2cf2b25b83fdd31a.1533836122.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.17.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
For some reason, t/t5552-skipping-fetch-negotiator.sh fails particularly
often on Windows due to racy tracing where the `git upload-pack` and the
`git fetch` processes compete for the same file.
We just introduced a remedy that uses fcntl(), but Windows does not have
fcntl(). So let's implement an alternative.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
compat/mingw.c | 19 +++++++++++++++++++
compat/mingw.h | 3 +++
config.mak.uname | 3 +++
3 files changed, 25 insertions(+)
diff --git a/compat/mingw.c b/compat/mingw.c
index 6ded1c859..6da9ce861 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -514,6 +514,25 @@ int mingw_chmod(const char *filename, int mode)
return _wchmod(wfilename, mode);
}
+int mingw_lock_or_unlock_fd_for_appending(int fd, int lock_it)
+{
+ HANDLE handle = (HANDLE)_get_osfhandle(fd);
+ OVERLAPPED overlapped = { 0 };
+ DWORD err;
+
+ if (!lock_it && UnlockFileEx(handle, 0, -1, 0, &overlapped))
+ return 0;
+ if (lock_it &&
+ LockFileEx(handle, LOCKFILE_EXCLUSIVE_LOCK, 0, -1, 0, &overlapped))
+ return 0;
+
+ err = GetLastError();
+ /* LockFileEx() cannot lock pipes */
+ errno = err == ERROR_INVALID_FUNCTION ?
+ EBADF : err_win_to_posix(GetLastError());
+ return -1;
+}
+
/*
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
diff --git a/compat/mingw.h b/compat/mingw.h
index 571019d0b..0f76d89a9 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -397,6 +397,9 @@ HANDLE winansi_get_osfhandle(int fd);
* git specific compatibility
*/
+int mingw_lock_or_unlock_fd_for_appending(int fd, int lock_it);
+#define lock_or_unlock_fd_for_appending mingw_lock_or_unlock_fd_for_appending
+
#define has_dos_drive_prefix(path) \
(isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
int mingw_skip_dos_drive_prefix(char **path);
diff --git a/config.mak.uname b/config.mak.uname
index 684fc5bf0..159b7da81 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -376,6 +376,7 @@ ifeq ($(uname_S),Windows)
NO_POSIX_GOODIES = UnfortunatelyYes
NATIVE_CRLF = YesPlease
DEFAULT_HELP_FORMAT = html
+ HAVE_FLOCK = YesWeEmulate
CC = compat/vcbuild/scripts/clink.pl
AR = compat/vcbuild/scripts/lib.pl
@@ -523,6 +524,8 @@ ifneq (,$(findstring MINGW,$(uname_S)))
NO_INET_NTOP = YesPlease
NO_POSIX_GOODIES = UnfortunatelyYes
DEFAULT_HELP_FORMAT = html
+ HAVE_FLOCK = YesWeEmulate
+
COMPAT_CFLAGS += -DNOGDI -Icompat -Icompat/win32
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
--
gitgitgadget
next prev parent reply other threads:[~2018-08-09 17:35 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-09 17:35 [PATCH 0/4] t5552: fix flakiness by introducing proper locking for GIT_TRACE Johannes Schindelin via GitGitGadget
2018-08-09 17:35 ` [PATCH 1/4] Introduce a function to lock/unlock file descriptors when appending Johannes Schindelin via GitGitGadget
2018-08-09 19:01 ` Junio C Hamano
2018-08-10 18:32 ` Johannes Schindelin
2018-08-09 17:35 ` Johannes Schindelin via GitGitGadget [this message]
2018-08-09 17:35 ` [PATCH 3/4] trace: lock the trace file to avoid racy trace_write() calls Johannes Schindelin via GitGitGadget
2018-08-09 17:35 ` [PATCH 4/4] trace: verify that locking works Johannes Schindelin via GitGitGadget
2018-08-09 19:47 ` [PATCH 0/4] t5552: fix flakiness by introducing proper locking for GIT_TRACE Jeff King
2018-08-09 20:49 ` Junio C Hamano
2018-08-09 21:08 ` Junio C Hamano
2018-08-09 21:32 ` Jeff King
2018-08-10 14:09 ` Jeff King
2018-08-10 15:58 ` Junio C Hamano
2018-08-10 15:58 ` Junio C Hamano
2018-08-10 16:43 ` Johannes Schindelin
2018-08-10 17:15 ` Jeff King
2018-08-10 18:40 ` Junio C Hamano
2018-08-10 19:34 ` Johannes Schindelin
2018-08-10 16:15 ` Johannes Sixt
2018-08-10 16:51 ` Jeff Hostetler
2018-08-10 16:57 ` Jeff Hostetler
2018-08-10 17:08 ` Johannes Sixt
2018-08-10 18:34 ` Junio C Hamano
2018-08-10 18:56 ` Jeff King
2018-08-13 19:02 ` [PATCH] mingw: enable atomic O_APPEND Johannes Sixt
2018-08-13 20:20 ` Junio C Hamano
2018-08-13 21:05 ` Johannes Sixt
2018-08-13 21:22 ` Ævar Arnfjörð Bjarmason
2018-08-13 21:55 ` Junio C Hamano
2018-08-13 22:37 ` Jeff King
2018-08-14 13:47 ` Ævar Arnfjörð Bjarmason
2018-08-14 14:53 ` Jeff King
2018-08-14 18:29 ` Johannes Sixt
2018-08-14 19:17 ` Jeff King
2018-08-14 13:01 ` Jeff Hostetler
2018-08-14 14:38 ` Junio C Hamano
2018-08-10 19:47 ` [PATCH v2 0/4] t5552: fix flakiness by introducing proper locking for GIT_TRACE Johannes Schindelin via GitGitGadget
2018-08-10 19:47 ` [PATCH v2 1/4] Introduce a function to lock/unlock file descriptors when appending Johannes Schindelin via GitGitGadget
2018-08-10 20:05 ` Junio C Hamano
2018-08-10 21:31 ` Johannes Schindelin
2018-08-10 19:47 ` [PATCH v2 2/4] mingw: implement lock_or_unlock_fd_for_appending() Johannes Schindelin via GitGitGadget
2018-08-10 19:47 ` [PATCH v2 3/4] trace: lock the trace file to avoid racy trace_write() calls Johannes Schindelin via GitGitGadget
2018-08-10 19:47 ` [PATCH v2 4/4] trace: verify that locking works Johannes Schindelin via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8dda2d5303952306520bc90c2cf2b25b83fdd31a.1533836122.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).