git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fsmonitor: handle differences between Windows named pipe functions
@ 2023-03-24 17:14 Eric DeCosta via GitGitGadget
  2023-03-27 11:37 ` Johannes Schindelin
  2023-04-10 19:46 ` [PATCH v2] " Eric DeCosta via GitGitGadget
  0 siblings, 2 replies; 12+ messages in thread
From: Eric DeCosta via GitGitGadget @ 2023-03-24 17:14 UTC (permalink / raw)
  To: git; +Cc: Eric DeCosta, Eric DeCosta

From: Eric DeCosta <edecosta@mathworks.com>

CreateNamedPipeW is perfectly happy accepting pipe names with seemingly
embedded escape charcters (e.g. \b), WaitNamedPipeW is not and incorrectly
returns ERROR_FILE_NOT_FOUND when clearly a named pipe, succesfully created
with CreateNamedPipeW, exists.

For example, this network path is problemmatic:
\\batfs-sb29-cifs\vmgr\sbs29\my_git_repo

In order to work around this issue, rather than using the path to the
worktree directly as the name of the pipe, instead use the hash of the
worktree path.

Signed-off-by: Eric DeCosta <edecosta@mathworks.com>
---
    fsmonitor: handle differences between Windows named pipe functions
    
    CreateNamedPipeW is perfectly happy accepting pipe names with embedded
    escape charcters (e.g. \b), WaitNamedPipeW is not and incorrectly
    returns ERROR_FILE_NOT_FOUND when clearly a named pipe with the given
    name exists.
    
    For example, this path is problemmatic:
    \batfs-sb29-cifs\vmgr\sbs29\my_git_repo
    
    In order to work around this issue, rather than using the path to the
    worktree directly as the name of the pipe, instead use the hash of the
    worktree path.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1503%2Fedecosta-mw%2Ffsmonitor_windows-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1503/edecosta-mw/fsmonitor_windows-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1503

 compat/simple-ipc/ipc-win32.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c
index 20ea7b65e0b..867590abd10 100644
--- a/compat/simple-ipc/ipc-win32.c
+++ b/compat/simple-ipc/ipc-win32.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "hex.h"
 #include "simple-ipc.h"
 #include "strbuf.h"
 #include "pkt-line.h"
@@ -17,27 +18,27 @@
 static int initialize_pipe_name(const char *path, wchar_t *wpath, size_t alloc)
 {
 	int off = 0;
-	struct strbuf realpath = STRBUF_INIT;
-
-	if (!strbuf_realpath(&realpath, path, 0))
-		return -1;
+	int ret = 0;
+	git_SHA_CTX sha1ctx;
+	struct strbuf real_path = STRBUF_INIT;
+	struct strbuf pipe_name = STRBUF_INIT;
+	unsigned char hash[GIT_MAX_RAWSZ];
 
-	off = swprintf(wpath, alloc, L"\\\\.\\pipe\\");
-	if (xutftowcs(wpath + off, realpath.buf, alloc - off) < 0)
+	if (!strbuf_realpath(&real_path, path, 0))
 		return -1;
 
-	/* Handle drive prefix */
-	if (wpath[off] && wpath[off + 1] == L':') {
-		wpath[off + 1] = L'_';
-		off += 2;
-	}
+	git_SHA1_Init(&sha1ctx);
+	git_SHA1_Update(&sha1ctx, real_path.buf, real_path.len);
+	git_SHA1_Final(hash, &sha1ctx);
+	strbuf_release(&real_path);
 
-	for (; wpath[off]; off++)
-		if (wpath[off] == L'/')
-			wpath[off] = L'\\';
+	strbuf_addf(&pipe_name, "git-fsmonitor-%s", hash_to_hex(hash));
+	off = swprintf(wpath, alloc, L"\\\\.\\pipe\\");
+	if (xutftowcs(wpath + off, pipe_name.buf, alloc - off) < 0)
+		ret = -1;
 
-	strbuf_release(&realpath);
-	return 0;
+	strbuf_release(&pipe_name);
+	return ret;
 }
 
 static enum ipc_active_state get_active_state(wchar_t *pipe_path)

base-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-05-15 21:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-24 17:14 [PATCH] fsmonitor: handle differences between Windows named pipe functions Eric DeCosta via GitGitGadget
2023-03-27 11:37 ` Johannes Schindelin
2023-03-27 15:02   ` Jeff Hostetler
2023-03-27 16:08     ` Junio C Hamano
2023-04-06 19:08     ` Eric DeCosta
2023-04-07 20:55       ` Jeff Hostetler
2023-04-10 19:46 ` [PATCH v2] " Eric DeCosta via GitGitGadget
2023-04-22 20:00   ` Eric DeCosta
2023-04-26 20:33     ` Jeff Hostetler
2023-04-27 13:45       ` Jeff Hostetler
2023-05-08 20:30       ` Eric DeCosta
2023-05-15 21:50         ` Jeff Hostetler

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).