summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2013-11-05 04:48:45 -0800
committerEdward Thomson <ethomson@edwardthomson.com>2013-11-05 04:48:45 -0800
commit3ae66ef1af2af9132c96c57bf5c6e2cfdb1f617c (patch)
tree8615cf3c6a3cbfe454d108896b3b6b7d3904d531 /tests-clar
parentb47949254ee5b7e5801fd3d1d80136bff5db938a (diff)
parent1d3a8aeb4bd032d0bf34039fbcb308fba06b862a (diff)
downloadlibgit2-3ae66ef1af2af9132c96c57bf5c6e2cfdb1f617c.tar.gz
Merge pull request #1940 from ethomson/filebuf_umask
Take umask into account in filebuf_commit
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/config/stress.c4
-rw-r--r--tests-clar/core/filebuf.c50
-rw-r--r--tests-clar/index/tests.c6
-rw-r--r--tests-clar/odb/alternates.c4
4 files changed, 49 insertions, 15 deletions
diff --git a/tests-clar/config/stress.c b/tests-clar/config/stress.c
index 8cc64d23c..eeca54ff4 100644
--- a/tests-clar/config/stress.c
+++ b/tests-clar/config/stress.c
@@ -10,12 +10,12 @@ void test_config_stress__initialize(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
- cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0));
+ cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0, 0666));
git_filebuf_printf(&file, "[color]\n\tui = auto\n");
git_filebuf_printf(&file, "[core]\n\teditor = \n");
- cl_git_pass(git_filebuf_commit(&file, 0666));
+ cl_git_pass(git_filebuf_commit(&file));
}
void test_config_stress__cleanup(void)
diff --git a/tests-clar/core/filebuf.c b/tests-clar/core/filebuf.c
index bf2167057..5a3e7510f 100644
--- a/tests-clar/core/filebuf.c
+++ b/tests-clar/core/filebuf.c
@@ -13,7 +13,7 @@ void test_core_filebuf__0(void)
cl_must_pass(fd);
cl_must_pass(p_close(fd));
- cl_git_fail(git_filebuf_open(&file, test, 0));
+ cl_git_fail(git_filebuf_open(&file, test, 0, 0666));
cl_assert(git_path_exists(testlock));
cl_must_pass(p_unlink(testlock));
@@ -28,9 +28,9 @@ void test_core_filebuf__1(void)
cl_git_mkfile(test, "libgit2 rocks\n");
- cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND));
+ cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND, 0666));
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
- cl_git_pass(git_filebuf_commit(&file, 0666));
+ cl_git_pass(git_filebuf_commit(&file));
cl_assert_equal_file("libgit2 rocks\nlibgit2 rocks\n", 0, test);
@@ -47,9 +47,9 @@ void test_core_filebuf__2(void)
memset(buf, 0xfe, sizeof(buf));
- cl_git_pass(git_filebuf_open(&file, test, 0));
+ cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
cl_git_pass(git_filebuf_write(&file, buf, sizeof(buf)));
- cl_git_pass(git_filebuf_commit(&file, 0666));
+ cl_git_pass(git_filebuf_commit(&file));
cl_assert_equal_file((char *)buf, sizeof(buf), test);
@@ -64,7 +64,7 @@ void test_core_filebuf__4(void)
cl_assert(file.buffer == NULL);
- cl_git_pass(git_filebuf_open(&file, test, 0));
+ cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
cl_assert(file.buffer != NULL);
git_filebuf_cleanup(&file);
@@ -80,13 +80,47 @@ void test_core_filebuf__5(void)
cl_assert(file.buffer == NULL);
- cl_git_pass(git_filebuf_open(&file, test, 0));
+ cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
cl_assert(file.buffer != NULL);
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
cl_assert(file.buffer != NULL);
- cl_git_pass(git_filebuf_commit(&file, 0666));
+ cl_git_pass(git_filebuf_commit(&file));
cl_assert(file.buffer == NULL);
cl_must_pass(p_unlink(test));
}
+
+
+/* make sure git_filebuf_commit takes umask into account */
+void test_core_filebuf__umask(void)
+{
+ git_filebuf file = GIT_FILEBUF_INIT;
+ char test[] = "test";
+ struct stat statbuf;
+ mode_t mask, os_mask;
+
+#ifdef GIT_WIN32
+ os_mask = 0600;
+#else
+ os_mask = 0777;
+#endif
+
+ p_umask(mask = p_umask(0));
+
+ cl_assert(file.buffer == NULL);
+
+ cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
+ cl_assert(file.buffer != NULL);
+ cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
+ cl_assert(file.buffer != NULL);
+
+ cl_git_pass(git_filebuf_commit(&file));
+ cl_assert(file.buffer == NULL);
+
+ cl_must_pass(p_stat("test", &statbuf));
+ cl_assert_equal_i(statbuf.st_mode & os_mask, (0666 & ~mask) & os_mask);
+
+ cl_must_pass(p_unlink(test));
+}
+
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 09b05bf6e..e5202980c 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -224,9 +224,9 @@ void test_index_tests__add(void)
/* Create a new file in the working directory */
cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
- cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0));
+ cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0, 0666));
cl_git_pass(git_filebuf_write(&file, "hey there\n", 10));
- cl_git_pass(git_filebuf_commit(&file, 0666));
+ cl_git_pass(git_filebuf_commit(&file));
/* Store the expected hash of the file/blob
* This has been generated by executing the following
@@ -474,7 +474,7 @@ void test_index_tests__elocked(void)
cl_git_pass(git_repository_index(&index, repo));
/* Lock the index file so we fail to lock it */
- cl_git_pass(git_filebuf_open(&file, index->index_file_path, 0));
+ cl_git_pass(git_filebuf_open(&file, index->index_file_path, 0, 0666));
error = git_index_write(index);
cl_assert_equal_i(GIT_ELOCKED, error);
diff --git a/tests-clar/odb/alternates.c b/tests-clar/odb/alternates.c
index 4e876c2b3..c75f6feaa 100644
--- a/tests-clar/odb/alternates.c
+++ b/tests-clar/odb/alternates.c
@@ -32,9 +32,9 @@ static void init_linked_repo(const char *path, const char *alternate)
cl_git_pass(git_futils_mkdir(filepath.ptr, NULL, 0755, GIT_MKDIR_PATH));
cl_git_pass(git_buf_joinpath(&filepath, filepath.ptr , "alternates"));
- cl_git_pass(git_filebuf_open(&file, git_buf_cstr(&filepath), 0));
+ cl_git_pass(git_filebuf_open(&file, git_buf_cstr(&filepath), 0, 0666));
git_filebuf_printf(&file, "%s\n", git_buf_cstr(&destpath));
- cl_git_pass(git_filebuf_commit(&file, 0644));
+ cl_git_pass(git_filebuf_commit(&file));
git_repository_free(repo);
}