summaryrefslogtreecommitdiff
path: root/src/fileops.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 /src/fileops.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 'src/fileops.c')
-rw-r--r--src/fileops.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/fileops.c b/src/fileops.c
index da9c55f14..ff36b007e 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -31,9 +31,8 @@ int git_futils_mv_atomic(const char *from, const char *to)
#endif
}
-int git_futils_mkpath2file(const char *file_path)
+int git_futils_mkpath2file(const char *file_path, const mode_t mode)
{
- const mode_t mode = 0755; /* or 0777 ? */
int error = GIT_SUCCESS;
char target_folder_path[GIT_PATH_MAX];
@@ -67,9 +66,9 @@ int git_futils_mktmp(char *path_out, const char *filename)
return fd;
}
-int git_futils_creat_withpath(const char *path, const mode_t mode)
+int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode)
{
- if (git_futils_mkpath2file(path) < GIT_SUCCESS)
+ if (git_futils_mkpath2file(path, dirmode) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to create file %s", path);
return p_creat(path, mode);
@@ -81,9 +80,9 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
return fd >= 0 ? fd : git__throw(GIT_EOSERR, "Failed to create locked file. Could not open %s", path);
}
-int git_futils_creat_locked_withpath(const char *path, const mode_t mode)
+int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode)
{
- if (git_futils_mkpath2file(path) < GIT_SUCCESS)
+ if (git_futils_mkpath2file(path, dirmode) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to create locked file %s", path);
return git_futils_creat_locked(path, mode);
@@ -212,9 +211,9 @@ void git_futils_freebuffer(git_fbuffer *obj)
}
-int git_futils_mv_withpath(const char *from, const char *to)
+int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode)
{
- if (git_futils_mkpath2file(to) < GIT_SUCCESS)
+ if (git_futils_mkpath2file(to, dirmode) < GIT_SUCCESS)
return GIT_EOSERR; /* The callee already takes care of setting the correct error message. */
return git_futils_mv_atomic(from, to); /* The callee already takes care of setting the correct error message. */