Skip to content

Commit 8d54822

Browse files
committed
tests: verify that futils_mktmp respects umask
1 parent e2e3f3e commit 8d54822

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/core/futils.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,29 @@ void test_core_futils__recursive_rmdir_keeps_symlink_targets(void)
8787
cl_must_pass(p_rmdir("dir-target"));
8888
cl_must_pass(p_unlink("file-target"));
8989
}
90+
91+
void test_core_futils__mktmp_umask(void)
92+
{
93+
#ifdef GIT_WIN32
94+
cl_skip();
95+
#else
96+
git_str path = GIT_STR_INIT;
97+
struct stat st;
98+
int fd;
99+
100+
umask(0);
101+
cl_assert((fd = git_futils_mktmp(&path, "foo", 0777)) >= 0);
102+
cl_must_pass(p_fstat(fd, &st));
103+
cl_assert_equal_i(st.st_mode & 0777, 0777);
104+
cl_must_pass(p_unlink(path.ptr));
105+
close(fd);
106+
107+
umask(077);
108+
cl_assert((fd = git_futils_mktmp(&path, "foo", 0777)) >= 0);
109+
cl_must_pass(p_fstat(fd, &st));
110+
cl_assert_equal_i(st.st_mode & 0777, 0700);
111+
cl_must_pass(p_unlink(path.ptr));
112+
close(fd);
113+
git_str_dispose(&path);
114+
#endif
115+
}

0 commit comments

Comments
 (0)