|
1 | 1 | #include "cache.h"
|
| 2 | +#include "hex.h" |
2 | 3 | #include "simple-ipc.h"
|
3 | 4 | #include "strbuf.h"
|
4 | 5 | #include "pkt-line.h"
|
|
17 | 18 | static int initialize_pipe_name(const char *path, wchar_t *wpath, size_t alloc)
|
18 | 19 | {
|
19 | 20 | int off = 0;
|
20 |
| - struct strbuf realpath = STRBUF_INIT; |
21 |
| - |
22 |
| - if (!strbuf_realpath(&realpath, path, 0)) |
23 |
| - return -1; |
| 21 | + int ret = 0; |
| 22 | + git_SHA_CTX sha1ctx; |
| 23 | + struct strbuf real_path = STRBUF_INIT; |
| 24 | + struct strbuf pipe_name = STRBUF_INIT; |
| 25 | + unsigned char hash[GIT_MAX_RAWSZ]; |
24 | 26 |
|
25 |
| - off = swprintf(wpath, alloc, L"\\\\.\\pipe\\"); |
26 |
| - if (xutftowcs(wpath + off, realpath.buf, alloc - off) < 0) |
| 27 | + if (!strbuf_realpath(&real_path, path, 0)) |
27 | 28 | return -1;
|
28 | 29 |
|
29 |
| - /* Handle drive prefix */ |
30 |
| - if (wpath[off] && wpath[off + 1] == L':') { |
31 |
| - wpath[off + 1] = L'_'; |
32 |
| - off += 2; |
33 |
| - } |
| 30 | + git_SHA1_Init(&sha1ctx); |
| 31 | + git_SHA1_Update(&sha1ctx, real_path.buf, real_path.len); |
| 32 | + git_SHA1_Final(hash, &sha1ctx); |
| 33 | + strbuf_release(&real_path); |
34 | 34 |
|
35 |
| - for (; wpath[off]; off++) |
36 |
| - if (wpath[off] == L'/') |
37 |
| - wpath[off] = L'\\'; |
| 35 | + strbuf_addf(&pipe_name, "git-fsmonitor-%s", hash_to_hex(hash)); |
| 36 | + off = swprintf(wpath, alloc, L"\\\\.\\pipe\\"); |
| 37 | + if (xutftowcs(wpath + off, pipe_name.buf, alloc - off) < 0) |
| 38 | + ret = -1; |
38 | 39 |
|
39 |
| - strbuf_release(&realpath); |
40 |
| - return 0; |
| 40 | + strbuf_release(&pipe_name); |
| 41 | + return ret; |
41 | 42 | }
|
42 | 43 |
|
43 | 44 | static enum ipc_active_state get_active_state(wchar_t *pipe_path)
|
|
0 commit comments