Re: [PATCH v3 19/34] fsmonitor-fs-listen-win32: implement FSMonitor backend on Windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 7/6/21 3:09 PM, Johannes Schindelin wrote:
Hi Jeff,


On Thu, 1 Jul 2021, Jeff Hostetler via GitGitGadget wrote:

Jeff Hostetler <jeffhost@xxxxxxxxxxxxx>

the win32 backend to register a watch on the working tree
irectory (recursively).  Also watch the <gitdir> if it is
side the working tree.  And to collect path change notifications
atches and publish.

-off-by: Jeff Hostetler <jeffhost@xxxxxxxxxxxxx>

t/fsmonitor/fsmonitor-fs-listen-win32.c | 530 +++++++++++++++++++
e changed, 530 insertions(+)

diff --git a/compat/fsmonitor/fsmonitor-fs-listen-win32.c b/compat/fsmonitor/fsmonitor-fs-listen-win32.c
index 880446b49e3..d707d47a0d7 100644
--- a/compat/fsmonitor/fsmonitor-fs-listen-win32.c
+++ b/compat/fsmonitor/fsmonitor-fs-listen-win32.c
@@ -2,20 +2,550 @@
+ [...]
+
+static struct one_watch *create_watch(struct fsmonitor_daemon_state *state,
+				      const char *path)
+{
+	struct one_watch *watch = NULL;
+	DWORD desired_access = FILE_LIST_DIRECTORY;
+	DWORD share_mode =
+		FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE;
+	HANDLE hDir;
+
+	hDir = CreateFileA(path,
+			   desired_access, share_mode, NULL, OPEN_EXISTING,
+			   FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
+			   NULL);

The `*A()` family of Win32 API functions disagree with Git in one very
interesting aspect: Git always assumes UTF-8, while e.g. `CreateFileA()`
will use the current Win32 locale to internally transform to wide
characters and then call `CreateFileW()`.

This poses no problem when your locale is US American and your paths
contain no non-ASCII characters.

In the Git for Windows bug tracker, it was reported that it _does_ cause
problems when venturing outside such a cozy scenario (for full details,
see https://github.com/git-for-windows/git/issues/3262)

I need this (and merged it before starting the process to release Git for
Windows v2.32.0(2)) to fix that (could I ask you to integrate this in case
a re-roll will become necessary?):

-- snipsnap --
From: Johannes Schindelin <johannes.schindelin@xxxxxx>
Date: Mon, 5 Jul 2021 13:51:05 +0200
Subject: [PATCH] fixup! fsmonitor-fs-listen-win32: implement FSMonitor backend
  on Windows

Let's keep avoiding the `*A()` family of Win32 API functions because
they are susceptible to incoherent encoding problems. In Git for
Windows, we always assume paths to be UTF-8 encoded. Let's use the
dedicated helper to convert such a path to the wide character version,
and then use the `*W()` function instead.

Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx>
---
  compat/fsmonitor/fsmonitor-fs-listen-win32.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/compat/fsmonitor/fsmonitor-fs-listen-win32.c b/compat/fsmonitor/fsmonitor-fs-listen-win32.c
index ba087b292df..3b42ab311d9 100644
--- a/compat/fsmonitor/fsmonitor-fs-listen-win32.c
+++ b/compat/fsmonitor/fsmonitor-fs-listen-win32.c
@@ -111,8 +111,14 @@ static struct one_watch *create_watch(struct fsmonitor_daemon_state *state,
  	DWORD share_mode =
  		FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE;
  	HANDLE hDir;
+	wchar_t wpath[MAX_PATH];

-	hDir = CreateFileA(path,
+	if (xutftowcs_path(wpath, path) < 0) {
+		error(_("could not convert to wide characters: '%s'"), path);
+		return NULL;
+	}
+
+	hDir = CreateFileW(wpath,
  			   desired_access, share_mode, NULL, OPEN_EXISTING,
  			   FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
  			   NULL);
--
2.32.0.windows.1.15.gf1590a75e2d


Thanks for the heads up.  I'll pull this into my next release.
Jeff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux