diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-05-17 14:39:19 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-05-17 14:39:19 -0700 |
commit | 65ba3f73061f8c9992231ac36cb2bd99fa62665f (patch) | |
tree | f12ae255668b9bb7c37aec2777ed9dc3776f4b77 | |
parent | 5f9467582cde9e5e8b9819c8c5a44902db74594e (diff) | |
parent | 3ff774e34fbb11e1e67ad33a5cb2277181b92923 (diff) | |
download | git-65ba3f73061f8c9992231ac36cb2bd99fa62665f.tar.gz |
Merge branch 'ed/fsmonitor-windows-named-pipe' into seen
Fix fsmonitor on Windows when the filesystem path contains certain
characters.
* ed/fsmonitor-windows-named-pipe:
fsmonitor: handle differences between Windows named pipe functions
-rw-r--r-- | compat/simple-ipc/ipc-win32.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c index 8bfe51248e..5276f658a1 100644 --- a/compat/simple-ipc/ipc-win32.c +++ b/compat/simple-ipc/ipc-win32.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "abspath.h" #include "gettext.h" +#include "hex.h" #include "simple-ipc.h" #include "strbuf.h" #include "pkt-line.h" @@ -21,27 +22,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) |