From ce8cd006ce3adcd012a38401b8a7555ba3307b3f Mon Sep 17 00:00:00 2001 From: Brodie Rao Date: Wed, 7 Sep 2011 15:32:44 -0700 Subject: fileops/repository: create (most) directories with 0777 permissions To further match how Git behaves, this change makes most of the directories libgit2 creates in a git repo have a file mode of 0777. Specifically: - Intermediate directories created with git_futils_mkpath2file() have 0777 permissions. This affects odb_loose, reflog, and refs. - The top level folder for bare repos is created with 0777 permissions. - The top level folder for non-bare repos is created with 0755 permissions. - /objects/info/, /objects/pack/, /refs/heads/, and /refs/tags/ are created with 0777 permissions. Additionally, the following changes have been made: - fileops functions that create intermediate directories have grown a new dirmode parameter. The only exception to this is filebuf's lock_file(), which unconditionally creates intermediate directories with 0777 permissions when GIT_FILEBUF_FORCE is set. - The test runner now sets the umask to 0 before running any tests. This ensurses all file mode checks are consistent across systems. - t09-tree.c now does a directory permissions check. I've avoided adding this check to other tests that might reuse existing directories from the prefabricated test repos. Because they're checked into the repo, they have 0755 permissions. - Other assorted directories created by tests have 0777 permissions. --- tests-clay/core/dirent.c | 4 ++-- tests-clay/core/rmdir.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests-clay/core') diff --git a/tests-clay/core/dirent.c b/tests-clay/core/dirent.c index 73f571595..898b1227b 100644 --- a/tests-clay/core/dirent.c +++ b/tests-clay/core/dirent.c @@ -20,12 +20,12 @@ static void setup(walk_data *d) { name_data *n; - cl_must_pass(p_mkdir(top_dir, 0755)); + cl_must_pass(p_mkdir(top_dir, 0777)); cl_must_pass(p_chdir(top_dir)); if (strcmp(d->sub, ".") != 0) - cl_must_pass(p_mkdir(d->sub, 0755)); + cl_must_pass(p_mkdir(d->sub, 0777)); strcpy(path_buffer, d->sub); state_loc = d; diff --git a/tests-clay/core/rmdir.c b/tests-clay/core/rmdir.c index aa21c6a3d..03baecf23 100644 --- a/tests-clay/core/rmdir.c +++ b/tests-clay/core/rmdir.c @@ -7,22 +7,22 @@ void test_core_rmdir__initialize(void) { char path[GIT_PATH_MAX]; - cl_must_pass(p_mkdir(empty_tmp_dir, 0755)); + cl_must_pass(p_mkdir(empty_tmp_dir, 0777)); git_path_join(path, empty_tmp_dir, "/one"); - cl_must_pass(p_mkdir(path, 0755)); + cl_must_pass(p_mkdir(path, 0777)); git_path_join(path, empty_tmp_dir, "/one/two_one"); - cl_must_pass(p_mkdir(path, 0755)); + cl_must_pass(p_mkdir(path, 0777)); git_path_join(path, empty_tmp_dir, "/one/two_two"); - cl_must_pass(p_mkdir(path, 0755)); + cl_must_pass(p_mkdir(path, 0777)); git_path_join(path, empty_tmp_dir, "/one/two_two/three"); - cl_must_pass(p_mkdir(path, 0755)); + cl_must_pass(p_mkdir(path, 0777)); git_path_join(path, empty_tmp_dir, "/two"); - cl_must_pass(p_mkdir(path, 0755)); + cl_must_pass(p_mkdir(path, 0777)); } /* make sure empty dir can be deleted recusively */ -- cgit v1.2.1 From 01ad7b3a9ec8f5e465f94c2704e1e96b84f941c7 Mon Sep 17 00:00:00 2001 From: Brodie Rao Date: Tue, 6 Sep 2011 15:48:45 -0700 Subject: *: correct and codify various file permissions The following files now have 0444 permissions: - loose objects - pack indexes - pack files - packs downloaded by fetch - packs downloaded by the HTTP transport And the following files now have 0666 permissions: - config files - repository indexes - reflogs - refs This brings libgit2 more in line with Git. Note that git_filebuf_commit() and git_filebuf_commit_at() have both gained a new mode parameter. The latter change fixes an important issue where filebufs created with GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3) usage). Now we chmod() the file before renaming it into place. Tests have been added to confirm that new commit, tag, and tree objects are created with the right permissions. I don't have access to Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32". --- tests-clay/core/dirent.c | 2 +- tests-clay/core/filebuf.c | 6 +++--- tests-clay/core/rmdir.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests-clay/core') diff --git a/tests-clay/core/dirent.c b/tests-clay/core/dirent.c index 898b1227b..105e8d8f0 100644 --- a/tests-clay/core/dirent.c +++ b/tests-clay/core/dirent.c @@ -31,7 +31,7 @@ static void setup(walk_data *d) state_loc = d; for (n = d->names; n->name; n++) { - git_file fd = p_creat(n->name, 0600); + git_file fd = p_creat(n->name, 0666); cl_assert(fd >= 0); p_close(fd); n->count = 0; diff --git a/tests-clay/core/filebuf.c b/tests-clay/core/filebuf.c index e00e20497..e1ecb2798 100644 --- a/tests-clay/core/filebuf.c +++ b/tests-clay/core/filebuf.c @@ -27,14 +27,14 @@ void test_core_filebuf__1(void) int fd; char test[] = "test"; - fd = p_creat(test, 0644); + fd = p_creat(test, 0666); cl_must_pass(fd); cl_must_pass(p_write(fd, "libgit2 rocks\n", 14)); cl_must_pass(p_close(fd)); cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND)); cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); - cl_git_pass(git_filebuf_commit(&file)); + cl_git_pass(git_filebuf_commit(&file, 0666)); cl_must_pass(p_unlink(test)); } @@ -51,7 +51,7 @@ void test_core_filebuf__2(void) cl_git_pass(git_filebuf_open(&file, test, 0)); cl_git_pass(git_filebuf_write(&file, buf, sizeof(buf))); - cl_git_pass(git_filebuf_commit(&file)); + cl_git_pass(git_filebuf_commit(&file, 0666)); cl_must_pass(p_unlink(test)); } diff --git a/tests-clay/core/rmdir.c b/tests-clay/core/rmdir.c index 03baecf23..20cc8f5f0 100644 --- a/tests-clay/core/rmdir.c +++ b/tests-clay/core/rmdir.c @@ -39,7 +39,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void) git_path_join(file, empty_tmp_dir, "/two/file.txt"); - fd = p_creat(file, 0755); + fd = p_creat(file, 0666); cl_assert(fd >= 0); cl_must_pass(p_close(fd)); -- cgit v1.2.1 From 3286c408eccb18c525ca123383f3ebf5097441bc Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 28 Oct 2011 14:51:13 -0700 Subject: global: Properly use `git__` memory wrappers Ensure that all memory related functions (malloc, calloc, strdup, free, etc) are using their respective `git__` wrappers. --- tests-clay/core/path.c | 4 ++-- tests-clay/core/vector.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests-clay/core') diff --git a/tests-clay/core/path.c b/tests-clay/core/path.c index db8f33d21..c394c7285 100644 --- a/tests-clay/core/path.c +++ b/tests-clay/core/path.c @@ -11,7 +11,7 @@ check_dirname(const char *A, const char *B) cl_assert((dir2 = git_path_dirname(A)) != NULL); cl_assert(strcmp(dir2, B) == 0); - free(dir2); + git__free(dir2); } static void @@ -24,7 +24,7 @@ check_basename(const char *A, const char *B) cl_assert((base2 = git_path_basename(A)) != NULL); cl_assert(strcmp(base2, B) == 0); - free(base2); + git__free(base2); } static void diff --git a/tests-clay/core/vector.c b/tests-clay/core/vector.c index 44e6d873d..b8a853c60 100644 --- a/tests-clay/core/vector.c +++ b/tests-clay/core/vector.c @@ -59,8 +59,8 @@ void test_core_vector__2(void) git_vector_free(&x); - free(ptrs[0]); - free(ptrs[1]); + git__free(ptrs[0]); + git__free(ptrs[1]); } -- cgit v1.2.1