1 #include "git-compat-util.h"
6 #include "repository.h"
8 #include "fsmonitor-ll.h"
9 #include "fsmonitor-ipc.h"
10 #include "fsmonitor-path-utils.h"
12 static GIT_PATH_FUNC(fsmonitor_ipc__get_default_path
, "fsmonitor--daemon.ipc")
14 const char *fsmonitor_ipc__get_path(struct repository
*r
)
16 static const char *ipc_path
= NULL
;
18 char *sock_dir
= NULL
;
19 struct strbuf ipc_file
= STRBUF_INIT
;
20 unsigned char hash
[GIT_MAX_RAWSZ
];
23 BUG("No repository passed into fsmonitor_ipc__get_path");
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();
35 git_SHA1_Init(&sha1ctx
);
36 git_SHA1_Update(&sha1ctx
, r
->worktree
, strlen(r
->worktree
));
37 git_SHA1_Final(hash
, &sha1ctx
);
39 repo_config_get_string(r
, "fsmonitor.socketdir", &sock_dir
);
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
));
46 strbuf_addf(&ipc_file
, "~/.git-fsmonitor-%s", hash_to_hex(hash
));
50 ipc_path
= interpolate_path(ipc_file
.buf
, 1);
52 die(_("Invalid path: %s"), ipc_file
.buf
);
54 strbuf_release(&ipc_file
);