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