1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "git-compat-util.h"
8 #include "repository.h"
10 #include "fsmonitor-ll.h"
11 #include "fsmonitor-ipc.h"
12 #include "fsmonitor-path-utils.h"
14 static GIT_PATH_FUNC(fsmonitor_ipc__get_default_path
, "fsmonitor--daemon.ipc")
16 const char *fsmonitor_ipc__get_path(struct repository
*r
)
18 static const char *ipc_path
= NULL
;
20 char *sock_dir
= NULL
;
21 struct strbuf ipc_file
= STRBUF_INIT
;
22 unsigned char hash
[GIT_SHA1_RAWSZ
];
25 BUG("No repository passed into fsmonitor_ipc__get_path");
31 /* By default the socket file is created in the .git directory */
32 if (fsmonitor__is_fs_remote(r
->gitdir
) < 1) {
33 ipc_path
= fsmonitor_ipc__get_default_path();
37 git_SHA1_Init(&sha1ctx
);
38 git_SHA1_Update(&sha1ctx
, r
->worktree
, strlen(r
->worktree
));
39 git_SHA1_Final(hash
, &sha1ctx
);
41 repo_config_get_string(r
, "fsmonitor.socketdir", &sock_dir
);
43 /* Create the socket file in either socketDir or $HOME */
44 if (sock_dir
&& *sock_dir
) {
45 strbuf_addf(&ipc_file
, "%s/.git-fsmonitor-%s",
46 sock_dir
, hash_to_hex_algop(hash
, &hash_algos
[GIT_HASH_SHA1
]));
48 strbuf_addf(&ipc_file
, "~/.git-fsmonitor-%s",
49 hash_to_hex_algop(hash
, &hash_algos
[GIT_HASH_SHA1
]));
53 ipc_path
= interpolate_path(ipc_file
.buf
, 1);
55 die(_("Invalid path: %s"), ipc_file
.buf
);
57 strbuf_release(&ipc_file
);