From 33127043b3ef8dd8dd695ba3613eaa104a80a56b Mon Sep 17 00:00:00 2001 From: Brodie Rao Date: Fri, 14 Oct 2011 14:18:02 -0700 Subject: fileops/posix: replace usage of "int mode" with "mode_t mode" Note: Functions exported from fileops take const mode_t, while the underlying POSIX wrappers take mode_t. --- src/fileops.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/fileops.c') diff --git a/src/fileops.c b/src/fileops.c index 203cce0a4..da9c55f14 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -33,7 +33,7 @@ int git_futils_mv_atomic(const char *from, const char *to) int git_futils_mkpath2file(const char *file_path) { - const int mode = 0755; /* or 0777 ? */ + const mode_t mode = 0755; /* or 0777 ? */ int error = GIT_SUCCESS; char target_folder_path[GIT_PATH_MAX]; @@ -67,7 +67,7 @@ int git_futils_mktmp(char *path_out, const char *filename) return fd; } -int git_futils_creat_withpath(const char *path, int mode) +int git_futils_creat_withpath(const char *path, const mode_t mode) { if (git_futils_mkpath2file(path) < GIT_SUCCESS) return git__throw(GIT_EOSERR, "Failed to create file %s", path); @@ -75,13 +75,13 @@ int git_futils_creat_withpath(const char *path, int mode) return p_creat(path, mode); } -int git_futils_creat_locked(const char *path, int mode) +int git_futils_creat_locked(const char *path, const mode_t mode) { int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, 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, int mode) +int git_futils_creat_locked_withpath(const char *path, const mode_t mode) { if (git_futils_mkpath2file(path) < GIT_SUCCESS) return git__throw(GIT_EOSERR, "Failed to create locked file %s", path); @@ -289,7 +289,7 @@ int git_futils_direach( return GIT_SUCCESS; } -int git_futils_mkdir_r(const char *path, int mode) +int git_futils_mkdir_r(const char *path, const mode_t mode) { int error, root_path_offset; char *pp, *sp; -- cgit v1.2.1 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. --- src/fileops.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/fileops.c') 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. */ -- 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. --- src/fileops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/fileops.c') diff --git a/src/fileops.c b/src/fileops.c index 203cce0a4..c8de8d83d 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -181,7 +181,7 @@ int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mt if (p_read(fd, buff, len) < 0) { p_close(fd); - free(buff); + git__free(buff); return git__throw(GIT_ERROR, "Failed to read file `%s`", path); } buff[len] = '\0'; @@ -207,7 +207,7 @@ int git_futils_readbuffer(git_fbuffer *obj, const char *path) void git_futils_freebuffer(git_fbuffer *obj) { assert(obj); - free(obj->data); + git__free(obj->data); obj->data = NULL; } @@ -326,7 +326,7 @@ int git_futils_mkdir_r(const char *path, int mode) error = GIT_SUCCESS; } - free(path_copy); + git__free(path_copy); if (error < GIT_SUCCESS) return git__throw(error, "Failed to recursively create `%s` tree structure", path); -- cgit v1.2.1 From 0c49ec2d3b5bfc32d69d189b7dc69cc26beb6a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 7 Nov 2011 19:34:24 +0100 Subject: Implement p_rename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the callers of git_futils_mv_atomic to use p_rename. Signed-off-by: Carlos Martín Nieto --- src/fileops.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) (limited to 'src/fileops.c') diff --git a/src/fileops.c b/src/fileops.c index 2030c786d..955bb1bf6 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -8,29 +8,6 @@ #include "fileops.h" #include -int git_futils_mv_atomic(const char *from, const char *to) -{ -#ifdef GIT_WIN32 - /* - * Win32 POSIX compilance my ass. If the destination - * file exists, the `rename` call fails. This is as - * close as it gets with the Win32 API. - */ - return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) ? GIT_SUCCESS : GIT_EOSERR; -#else - /* Don't even try this on Win32 */ - if (!link(from, to)) { - p_unlink(from); - return GIT_SUCCESS; - } - - if (!rename(from, to)) - return GIT_SUCCESS; - - return GIT_ERROR; -#endif -} - int git_futils_mkpath2file(const char *file_path, const mode_t mode) { int error = GIT_SUCCESS; @@ -216,7 +193,7 @@ int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmod 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. */ + return p_rename(from, to); /* The callee already takes care of setting the correct error message. */ } int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len) -- cgit v1.2.1