Skip to content

Commit 3105992

Browse files
committed
Merge pull request libgit2#4169 from csware/absolute-symlink
2 parents e30a6ee + c10ce7c commit 3105992

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/filebuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static int resolve_symlink(git_buf *out, const char *path)
246246

247247
root = git_path_root(target.ptr);
248248
if (root >= 0) {
249-
if ((error = git_buf_puts(&curpath, target.ptr)) < 0)
249+
if ((error = git_buf_sets(&curpath, target.ptr)) < 0)
250250
goto cleanup;
251251
} else {
252252
git_buf dir = GIT_BUF_INIT;

tests/core/filebuf.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,35 @@ void test_core_filebuf__symlink_follow(void)
187187
cl_git_pass(git_futils_rmdir_r(dir, NULL, GIT_RMDIR_REMOVE_FILES));
188188
}
189189

190+
void test_core_filebuf__symlink_follow_absolute_paths(void)
191+
{
192+
git_filebuf file = GIT_FILEBUF_INIT;
193+
git_buf source = GIT_BUF_INIT, target = GIT_BUF_INIT;
194+
195+
#ifdef GIT_WIN32
196+
cl_skip();
197+
#endif
198+
199+
cl_git_pass(git_buf_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
200+
cl_git_pass(git_buf_joinpath(&target, clar_sandbox_path(), "linkdir/target"));
201+
cl_git_pass(p_mkdir("linkdir", 0777));
202+
cl_git_pass(p_symlink(target.ptr, source.ptr));
203+
204+
cl_git_pass(git_filebuf_open(&file, source.ptr, 0, 0666));
205+
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
206+
207+
cl_assert_equal_i(true, git_path_exists("linkdir/target.lock"));
208+
209+
cl_git_pass(git_filebuf_commit(&file));
210+
cl_assert_equal_i(true, git_path_exists("linkdir/target"));
211+
212+
git_filebuf_cleanup(&file);
213+
git_buf_free(&source);
214+
git_buf_free(&target);
215+
216+
cl_git_pass(git_futils_rmdir_r("linkdir", NULL, GIT_RMDIR_REMOVE_FILES));
217+
}
218+
190219
void test_core_filebuf__symlink_depth(void)
191220
{
192221
git_filebuf file = GIT_FILEBUF_INIT;

0 commit comments

Comments
 (0)