diff options
author | Vicent Martà <tanoku@gmail.com> | 2011-10-28 19:04:23 -0700 |
---|---|---|
committer | Vicent Martà <tanoku@gmail.com> | 2011-10-28 19:04:23 -0700 |
commit | 89fb8f025a1f72b90f1f9563c85bf43b7f66ba60 (patch) | |
tree | 11726793eecf4670d4948a22e276dd3d50d1addb /src/filebuf.c | |
parent | 3286c408eccb18c525ca123383f3ebf5097441bc (diff) | |
parent | 01ad7b3a9ec8f5e465f94c2704e1e96b84f941c7 (diff) | |
download | libgit2-89fb8f025a1f72b90f1f9563c85bf43b7f66ba60.tar.gz |
Merge pull request #456 from brodie/perm-fixes
Create objects, indexes, and directories with the right file permissions
Diffstat (limited to 'src/filebuf.c')
-rw-r--r-- | src/filebuf.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/filebuf.c b/src/filebuf.c index 3f57d295d..1a3fe6d9b 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -10,6 +10,8 @@ #include "filebuf.h" #include "fileops.h" +#define GIT_LOCK_FILE_MODE 0644 + static const size_t WRITE_BUFFER_SIZE = (4096 * 2); static int lock_file(git_filebuf *file, int flags) @@ -23,9 +25,10 @@ static int lock_file(git_filebuf *file, int flags) /* create path to the file buffer is required */ if (flags & GIT_FILEBUF_FORCE) { - file->fd = git_futils_creat_locked_withpath(file->path_lock, 0644); + /* XXX: Should dirmode here be configurable? Or is 0777 always fine? */ + file->fd = git_futils_creat_locked_withpath(file->path_lock, 0777, GIT_LOCK_FILE_MODE); } else { - file->fd = git_futils_creat_locked(file->path_lock, 0644); + file->fd = git_futils_creat_locked(file->path_lock, GIT_LOCK_FILE_MODE); } if (file->fd < 0) @@ -246,17 +249,17 @@ int git_filebuf_hash(git_oid *oid, git_filebuf *file) return GIT_SUCCESS; } -int git_filebuf_commit_at(git_filebuf *file, const char *path) +int git_filebuf_commit_at(git_filebuf *file, const char *path, mode_t mode) { git__free(file->path_original); file->path_original = git__strdup(path); if (file->path_original == NULL) return GIT_ENOMEM; - return git_filebuf_commit(file); + return git_filebuf_commit(file, mode); } -int git_filebuf_commit(git_filebuf *file) +int git_filebuf_commit(git_filebuf *file, mode_t mode) { int error; @@ -270,6 +273,11 @@ int git_filebuf_commit(git_filebuf *file) p_close(file->fd); file->fd = -1; + if (p_chmod(file->path_lock, mode)) { + error = git__throw(GIT_EOSERR, "Failed to chmod locked file before committing"); + goto cleanup; + } + error = git_futils_mv_atomic(file->path_lock, file->path_original); cleanup: |