diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-07-11 15:14:42 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-07-20 19:11:20 +0200 |
| commit | 50194dcda14a515bc3bbddee68c4092ca778d4dd (patch) | |
| tree | 62523d9a308f079f24e2e25201eadb6b3960c207 /tests/core | |
| parent | 93d37a1d5295b77731f2de238fffc7e01b9866b0 (diff) | |
| download | libgit2-50194dcda14a515bc3bbddee68c4092ca778d4dd.tar.gz | |
win32: fix symlinks to relative file targets
When creating a symlink in Windows, one needs to tell Windows whether
the symlink should be a file or directory symlink. To determine which
flag to pass, we call `GetFileAttributesW` on the target file to see
whether it is a directory and then pass the flag accordingly. The
problem though is if create a symlink with a relative target path, then
we will check that relative path while not necessarily being inside of
the working directory where the symlink is to be created. Thus, getting
its attributes will either fail or return attributes of the wrong
target.
Fix this by resolving the target path relative to the directory in which
the symlink is to be created.
Diffstat (limited to 'tests/core')
| -rw-r--r-- | tests/core/posix.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/core/posix.c b/tests/core/posix.c index 10d689a5f..dcc619f22 100644 --- a/tests/core/posix.c +++ b/tests/core/posix.c @@ -285,3 +285,27 @@ void test_core_posix__unlink_removes_symlink(void) cl_must_pass(p_unlink("file")); cl_must_pass(p_rmdir("dir")); } + +void test_core_posix__symlink_resolves_to_correct_type(void) +{ + git_buf contents = GIT_BUF_INIT; + + if (!git_path_supports_symlinks(clar_sandbox_path())) + clar__skip(); + + cl_must_pass(git_futils_mkdir("dir", 0777, 0)); + cl_must_pass(git_futils_mkdir("file", 0777, 0)); + cl_git_mkfile("dir/file", "symlink target"); + + cl_git_pass(p_symlink("file", "dir/link")); + + cl_git_pass(git_futils_readbuffer(&contents, "dir/file")); + cl_assert_equal_s(contents.ptr, "symlink target"); + + cl_must_pass(p_unlink("dir/link")); + cl_must_pass(p_unlink("dir/file")); + cl_must_pass(p_rmdir("dir")); + cl_must_pass(p_rmdir("file")); + + git_buf_dispose(&contents); +} |
