From 6f50cde5dff787cc5ba0eae7bd225550496a3708 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin 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 --- 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 ba087b292d..3b42ab311d 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_long_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);