/src/git/compat/fsmonitor/fsm-ipc-unix.c
Line | Count | Source |
1 | | #define USE_THE_REPOSITORY_VARIABLE |
2 | | |
3 | | #include "git-compat-util.h" |
4 | | #include "config.h" |
5 | | #include "gettext.h" |
6 | | #include "hex.h" |
7 | | #include "path.h" |
8 | | #include "repository.h" |
9 | | #include "strbuf.h" |
10 | | #include "fsmonitor-ll.h" |
11 | | #include "fsmonitor-ipc.h" |
12 | | #include "fsmonitor-path-utils.h" |
13 | | |
14 | | static GIT_PATH_FUNC(fsmonitor_ipc__get_default_path, "fsmonitor--daemon.ipc") |
15 | | |
16 | | const char *fsmonitor_ipc__get_path(struct repository *r) |
17 | 0 | { |
18 | 0 | static const char *ipc_path = NULL; |
19 | 0 | git_SHA_CTX sha1ctx; |
20 | 0 | char *sock_dir = NULL; |
21 | 0 | struct strbuf ipc_file = STRBUF_INIT; |
22 | 0 | unsigned char hash[GIT_SHA1_RAWSZ]; |
23 | |
|
24 | 0 | if (!r) |
25 | 0 | BUG("No repository passed into fsmonitor_ipc__get_path"); |
26 | | |
27 | 0 | if (ipc_path) |
28 | 0 | return ipc_path; |
29 | | |
30 | | |
31 | | /* By default the socket file is created in the .git directory */ |
32 | 0 | if (fsmonitor__is_fs_remote(r->gitdir) < 1) { |
33 | 0 | ipc_path = fsmonitor_ipc__get_default_path(); |
34 | 0 | return ipc_path; |
35 | 0 | } |
36 | | |
37 | 0 | git_SHA1_Init(&sha1ctx); |
38 | 0 | git_SHA1_Update(&sha1ctx, r->worktree, strlen(r->worktree)); |
39 | 0 | git_SHA1_Final(hash, &sha1ctx); |
40 | |
|
41 | 0 | repo_config_get_string(r, "fsmonitor.socketdir", &sock_dir); |
42 | | |
43 | | /* Create the socket file in either socketDir or $HOME */ |
44 | 0 | if (sock_dir && *sock_dir) { |
45 | 0 | strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s", |
46 | 0 | sock_dir, hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1])); |
47 | 0 | } else { |
48 | 0 | strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", |
49 | 0 | hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1])); |
50 | 0 | } |
51 | 0 | free(sock_dir); |
52 | |
|
53 | 0 | ipc_path = interpolate_path(ipc_file.buf, 1); |
54 | 0 | if (!ipc_path) |
55 | 0 | die(_("Invalid path: %s"), ipc_file.buf); |
56 | | |
57 | 0 | strbuf_release(&ipc_file); |
58 | 0 | return ipc_path; |
59 | 0 | } |