Skip to content

Commit 1e3a639

Browse files
authored
Merge pull request libgit2#5065 from danielgindi/feature/win32_symlink_dir
Support symlinks for directories in win32
2 parents 7f562f2 + 336e98b commit 1e3a639

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/win32/posix_w32.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,18 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
397397
int p_symlink(const char *target, const char *path)
398398
{
399399
git_win32_path target_w, path_w;
400+
DWORD dwFlags;
400401

401402
if (git_win32_path_from_utf8(path_w, path) < 0 ||
402403
git__utf8_to_16(target_w, MAX_PATH, target) < 0)
403404
return -1;
404405

405-
if (!CreateSymbolicLinkW(path_w, target_w,
406-
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE))
406+
dwFlags = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
407+
408+
if (GetFileAttributesW(target_w) & FILE_ATTRIBUTE_DIRECTORY)
409+
dwFlags |= SYMBOLIC_LINK_FLAG_DIRECTORY;
410+
411+
if (!CreateSymbolicLinkW(path_w, target_w, dwFlags))
407412
return -1;
408413

409414
return 0;

0 commit comments

Comments
 (0)