6 #include "fsmonitor-ipc.h"
7 #include "fsmonitor-path-utils.h"
9 static GIT_PATH_FUNC(fsmonitor_ipc__get_default_path
, "fsmonitor--daemon.ipc")
11 const char *fsmonitor_ipc__get_path(struct repository
*r
)
13 static const char *ipc_path
= NULL
;
15 char *sock_dir
= NULL
;
16 struct strbuf ipc_file
= STRBUF_INIT
;
17 unsigned char hash
[GIT_MAX_RAWSZ
];
20 BUG("No repository passed into fsmonitor_ipc__get_path");
26 /* By default the socket file is created in the .git directory */
27 if (fsmonitor__is_fs_remote(r
->gitdir
) < 1) {
28 ipc_path
= fsmonitor_ipc__get_default_path();
32 git_SHA1_Init(&sha1ctx
);
33 git_SHA1_Update(&sha1ctx
, r
->worktree
, strlen(r
->worktree
));
34 git_SHA1_Final(hash
, &sha1ctx
);
36 repo_config_get_string(r
, "fsmonitor.socketdir", &sock_dir
);
38 /* Create the socket file in either socketDir or $HOME */
39 if (sock_dir
&& *sock_dir
) {
40 strbuf_addf(&ipc_file
, "%s/.git-fsmonitor-%s",
41 sock_dir
, hash_to_hex(hash
));
43 strbuf_addf(&ipc_file
, "~/.git-fsmonitor-%s", hash_to_hex(hash
));
47 ipc_path
= interpolate_path(ipc_file
.buf
, 1);
49 die(_("Invalid path: %s"), ipc_file
.buf
);
51 strbuf_release(&ipc_file
);