Web lists-archives.com

[GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials




git-credential-cache will now use the socket
$XDG_CACHE_HOME/git/credential/socket if there is not already a socket
at ~/.git-credential-cache/socket. This ensures that if another process
already created a socket at the old location it will be used over the
new one if it exists.

Signed-off-by: Devin Lehmacher <lehmacdj@xxxxxxxxx>
---
 credential-cache.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/credential-cache.c b/credential-cache.c
index cc8a6ee19..75c917de7 100644
--- a/credential-cache.c
+++ b/credential-cache.c
@@ -83,6 +83,19 @@ static void do_cache(const char *socket, const char *action, int timeout,
 	strbuf_release(&buf);
 }
 
+static char* get_socket_path(void) {
+	char *home_socket;
+
+	home_socket = expand_user_path("~/.git_credential_cache/socket");
+	if (home_socket)
+		if (file_exists(home_socket))
+			return home_socket;
+		else
+			free(home_socket);
+
+	return xdg_cache_home("credential/socket");
+}
+
 int cmd_main(int argc, const char **argv)
 {
 	char *socket_path = NULL;
@@ -106,7 +119,7 @@ int cmd_main(int argc, const char **argv)
 	op = argv[0];
 
 	if (!socket_path)
-		socket_path = expand_user_path("~/.git-credential-cache/socket");
+		socket_path = get_socket_path();
 	if (!socket_path)
 		die("unable to find a suitable socket path; use --socket");
 
-- 
2.11.0