diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-09-17 16:58:38 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-09-17 17:11:38 +0300 |
commit | 0862ec2eb9529573ab46f3975defc0b7632bede4 (patch) | |
tree | d210c87e64c7b1059d1b426945904dd655ae2a8b /tests/core | |
parent | 08df66301ec677f6cd98175a914dc933e2fb43a9 (diff) |
core::mkdir tests: ensure we don't stomp symlinks in mkdir
In `mkdir` and `mkdir_r`, ensure that we don't try to remove symlinks
that are in our way.
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/mkdir.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/core/mkdir.c b/tests/core/mkdir.c index 11fecb118..8d487e594 100644 --- a/tests/core/mkdir.c +++ b/tests/core/mkdir.c @@ -222,6 +222,40 @@ void test_core_mkdir__chmods(void) check_mode(0777, st.st_mode); } +void test_core_mkdir__keeps_parent_symlinks(void) +{ +#ifndef GIT_WIN32 + git_buf path = GIT_BUF_INIT; + + cl_set_cleanup(cleanup_basic_dirs, NULL); + + /* make a directory */ + cl_assert(!git_path_isdir("d0")); + cl_git_pass(git_futils_mkdir("d0", 0755, 0)); + cl_assert(git_path_isdir("d0")); + + cl_must_pass(symlink("d0", "d1")); + cl_assert(git_path_islink("d1")); + + cl_git_pass(git_futils_mkdir("d1/foo/bar", 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS)); + cl_assert(git_path_islink("d1")); + cl_assert(git_path_isdir("d1/foo/bar")); + cl_assert(git_path_isdir("d0/foo/bar")); + + cl_must_pass(symlink("d0", "d2")); + cl_assert(git_path_islink("d2")); + + git_buf_joinpath(&path, clar_sandbox_path(), "d2/other/dir"); + + cl_git_pass(git_futils_mkdir(path.ptr, 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS)); + cl_assert(git_path_islink("d2")); + cl_assert(git_path_isdir("d2/other/dir")); + cl_assert(git_path_isdir("d0/other/dir")); + + git_buf_free(&path); +#endif +} + void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void) { struct stat st; |