diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-03-20 12:16:18 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-03-20 12:16:18 +0100 |
commit | 31059923bd34b514b046379bf5510d55e7505b5a (patch) | |
tree | 805972470a65425fd45287c5c6828ea98d7177a3 | |
parent | e30a6ee378ebf6781c078608ee788fa784757579 (diff) | |
parent | c10ce7c21a6f48839b118a0ff7417d9d75920ee7 (diff) | |
download | libgit2-31059923bd34b514b046379bf5510d55e7505b5a.tar.gz |
Merge pull request #4169 from csware/absolute-symlink
-rw-r--r-- | src/filebuf.c | 2 | ||||
-rw-r--r-- | tests/core/filebuf.c | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/filebuf.c b/src/filebuf.c index ef68b16f4..825b9c04c 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -246,7 +246,7 @@ static int resolve_symlink(git_buf *out, const char *path) root = git_path_root(target.ptr); if (root >= 0) { - if ((error = git_buf_puts(&curpath, target.ptr)) < 0) + if ((error = git_buf_sets(&curpath, target.ptr)) < 0) goto cleanup; } else { git_buf dir = GIT_BUF_INIT; diff --git a/tests/core/filebuf.c b/tests/core/filebuf.c index 04a380b20..ef7ac6bd9 100644 --- a/tests/core/filebuf.c +++ b/tests/core/filebuf.c @@ -187,6 +187,35 @@ void test_core_filebuf__symlink_follow(void) cl_git_pass(git_futils_rmdir_r(dir, NULL, GIT_RMDIR_REMOVE_FILES)); } +void test_core_filebuf__symlink_follow_absolute_paths(void) +{ + git_filebuf file = GIT_FILEBUF_INIT; + git_buf source = GIT_BUF_INIT, target = GIT_BUF_INIT; + +#ifdef GIT_WIN32 + cl_skip(); +#endif + + cl_git_pass(git_buf_joinpath(&source, clar_sandbox_path(), "linkdir/link")); + cl_git_pass(git_buf_joinpath(&target, clar_sandbox_path(), "linkdir/target")); + cl_git_pass(p_mkdir("linkdir", 0777)); + cl_git_pass(p_symlink(target.ptr, source.ptr)); + + cl_git_pass(git_filebuf_open(&file, source.ptr, 0, 0666)); + cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); + + cl_assert_equal_i(true, git_path_exists("linkdir/target.lock")); + + cl_git_pass(git_filebuf_commit(&file)); + cl_assert_equal_i(true, git_path_exists("linkdir/target")); + + git_filebuf_cleanup(&file); + git_buf_free(&source); + git_buf_free(&target); + + cl_git_pass(git_futils_rmdir_r("linkdir", NULL, GIT_RMDIR_REMOVE_FILES)); +} + void test_core_filebuf__symlink_depth(void) { git_filebuf file = GIT_FILEBUF_INIT; |