summaryrefslogtreecommitdiff
path: root/tests/test_helpers.c
diff options
context:
space:
mode:
authorBrodie Rao <brodie@bitheap.org>2011-09-07 15:32:44 -0700
committerBrodie Rao <brodie@bitheap.org>2011-10-14 16:04:34 -0700
commitce8cd006ce3adcd012a38401b8a7555ba3307b3f (patch)
tree349af6c2be958ffadf18b97391e6797d2ccdb162 /tests/test_helpers.c
parent33127043b3ef8dd8dd695ba3613eaa104a80a56b (diff)
downloadlibgit2-ce8cd006ce3adcd012a38401b8a7555ba3307b3f.tar.gz
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.
Diffstat (limited to 'tests/test_helpers.c')
-rw-r--r--tests/test_helpers.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/tests/test_helpers.c b/tests/test_helpers.c
index 0900430e1..7074e4822 100644
--- a/tests/test_helpers.c
+++ b/tests/test_helpers.c
@@ -42,7 +42,7 @@ int write_object_data(char *file, void *data, size_t len)
int write_object_files(const char *odb_dir, object_data *d)
{
- if (p_mkdir(odb_dir, 0755) < 0) {
+ if (p_mkdir(odb_dir, GIT_OBJECT_DIR_MODE) < 0) {
int err = errno;
fprintf(stderr, "can't make directory \"%s\"", odb_dir);
if (err == EEXIST)
@@ -51,7 +51,7 @@ int write_object_files(const char *odb_dir, object_data *d)
return -1;
}
- if ((p_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) {
+ if ((p_mkdir(d->dir, GIT_OBJECT_DIR_MODE) < 0) && (errno != EEXIST)) {
fprintf(stderr, "can't make object directory \"%s\"\n", d->dir);
return -1;
}
@@ -82,7 +82,7 @@ int remove_object_files(const char *odb_dir, object_data *d)
return 0;
}
-int remove_loose_object(const char *repository_folder, git_object *object)
+void locate_loose_object(const char *repository_folder, git_object *object, char **out, char **out_folder)
{
static const char *objects_folder = "objects/";
@@ -104,6 +104,40 @@ int remove_loose_object(const char *repository_folder, git_object *object)
ptr += GIT_OID_HEXSZ + 1;
*ptr = 0;
+ *out = full_path;
+
+ if (out_folder)
+ *out_folder = top_folder;
+}
+
+int loose_object_dir_mode(const char *repository_folder, git_object *object)
+{
+ char *object_path;
+ size_t pos;
+ struct stat st;
+
+ locate_loose_object(repository_folder, object, &object_path, NULL);
+
+ pos = strlen(object_path);
+ while (pos--) {
+ if (object_path[pos] == '/') {
+ object_path[pos] = 0;
+ break;
+ }
+ }
+
+ assert(p_stat(object_path, &st) == 0);
+ free(object_path);
+
+ return st.st_mode;
+}
+
+int remove_loose_object(const char *repository_folder, git_object *object)
+{
+ char *full_path, *top_folder;
+
+ locate_loose_object(repository_folder, object, &full_path, &top_folder);
+
if (p_unlink(full_path) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", full_path);
return -1;
@@ -141,7 +175,7 @@ int copy_file(const char *src, const char *dst)
if (git_futils_readbuffer(&source_buf, src) < GIT_SUCCESS)
return GIT_ENOTFOUND;
- dst_fd = git_futils_creat_withpath(dst, 0644);
+ dst_fd = git_futils_creat_withpath(dst, 0777, 0644);
if (dst_fd < 0)
goto cleanup;