Skip to content

Commit cf54907

Browse files
committed
fsmonitor: handle differences between Windows named pipe functions
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 <[email protected]>
1 parent 27d43aa commit cf54907

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

compat/simple-ipc/ipc-win32.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache.h"
2+
#include "hex.h"
23
#include "simple-ipc.h"
34
#include "strbuf.h"
45
#include "pkt-line.h"
@@ -17,27 +18,22 @@
1718
static int initialize_pipe_name(const char *path, wchar_t *wpath, size_t alloc)
1819
{
1920
int off = 0;
20-
struct strbuf realpath = STRBUF_INIT;
21+
int ret = 0;
22+
git_SHA_CTX sha1ctx;
23+
struct strbuf pipe_name = STRBUF_INIT;
24+
unsigned char hash[GIT_MAX_RAWSZ];
2125

22-
if (!strbuf_realpath(&realpath, path, 0))
23-
return -1;
26+
git_SHA1_Init(&sha1ctx);
27+
git_SHA1_Update(&sha1ctx, path, strlen(path));
28+
git_SHA1_Final(hash, &sha1ctx);
2429

30+
strbuf_addf(&pipe_name, "git-fsmonitor-%s", hash_to_hex(hash));
2531
off = swprintf(wpath, alloc, L"\\\\.\\pipe\\");
26-
if (xutftowcs(wpath + off, realpath.buf, alloc - off) < 0)
27-
return -1;
28-
29-
/* Handle drive prefix */
30-
if (wpath[off] && wpath[off + 1] == L':') {
31-
wpath[off + 1] = L'_';
32-
off += 2;
33-
}
34-
35-
for (; wpath[off]; off++)
36-
if (wpath[off] == L'/')
37-
wpath[off] = L'\\';
32+
if (xutftowcs(wpath + off, pipe_name.buf, alloc - off) < 0)
33+
ret = -1;
3834

39-
strbuf_release(&realpath);
40-
return 0;
35+
strbuf_release(&pipe_name);
36+
return ret;
4137
}
4238

4339
static enum ipc_active_state get_active_state(wchar_t *pipe_path)

0 commit comments

Comments
 (0)