Commit 37a7adb59c5075901bd64259e8a98ccef6f6f452

Daniel Cohen Gindi 2019-05-05T07:49:09

Support symlinks for directories in win32

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index fcaf77e..1f68111 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -402,8 +402,12 @@ int p_symlink(const char *target, const char *path)
 		git__utf8_to_16(target_w, MAX_PATH, target) < 0)
 		return -1;
 
-	if (!CreateSymbolicLinkW(path_w, target_w,
-	    SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE))
+	DWORD dwFlags = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
+
+	if (GetFileAttributesW(target_w) & FILE_ATTRIBUTE_DIRECTORY)
+		dwFlags |= SYMBOLIC_LINK_FLAG_DIRECTORY;
+
+	if (!CreateSymbolicLinkW(path_w, target_w, dwFlags))
 		return -1;
 
 	return 0;