diff options
author | Russell Belfer <rb@github.com> | 2012-07-31 17:02:54 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-08-22 16:07:19 -0700 |
commit | ca1b6e54095a7e28d468a832f143025feae6cd4f (patch) | |
tree | 0ff9b9fbf71cd4f0489985b64f57590687361cd2 /src/fileops.h | |
parent | 662880ca60e4d1662bb10648522242ac54797720 (diff) | |
download | libgit2-ca1b6e54095a7e28d468a832f143025feae6cd4f.tar.gz |
Add template dir and set gid to repo init
This extends git_repository_init_ext further with support for
initializing the repository from an external template directory
and with support for the "create shared" type flags that make a
set GID repository directory.
This also adds tests for much of the new functionality to the
existing `repo/init.c` test suite.
Also, this adds a bunch of new utility functions including a
very general purpose `git_futils_mkdir` (with the ability to
make paths and to chmod the paths post-creation) and a file
tree copying function `git_futils_cp_r`. Also, this includes
some new path functions that were useful to keep the code
simple.
Diffstat (limited to 'src/fileops.h')
-rw-r--r-- | src/fileops.h | 83 |
1 files changed, 77 insertions, 6 deletions
diff --git a/src/fileops.h b/src/fileops.h index edfcb7dd0..6f3450373 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -48,17 +48,47 @@ extern int git_futils_creat_locked(const char *path, const mode_t mode); extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode); /** - * Create a directory if it does not exist + * Create a path recursively + * + * If a base parameter is being passed, it's expected to be valued with a + * path pointing to an already existing directory. */ -extern int git_futils_mkdir_q(const char *path, const mode_t mode); +extern int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode); /** - * Create a path recursively + * Flags to pass to `git_futils_mkdir`. * - * If a base parameter is being passed, it's expected to be valued with a path pointing to an already - * exisiting directory. + * * GIT_MKDIR_EXCL is "exclusive" - i.e. generate an error if dir exists. + * * GIT_MKDIR_PATH says to make all components in the path. + * * GIT_MKDIR_CHMOD says to chmod the final directory entry after creation + * * GIT_MKDIR_CHMOD_PATH says to chmod each directory component in the path + * * GIT_MKDIR_SKIP_LAST says to leave off the last element of the path + * + * Note that the chmod options will be executed even if the directory already + * exists, unless GIT_MKDIR_EXCL is given. */ -extern int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode); +typedef enum { + GIT_MKDIR_EXCL = 1, + GIT_MKDIR_PATH = 2, + GIT_MKDIR_CHMOD = 4, + GIT_MKDIR_CHMOD_PATH = 8, + GIT_MKDIR_SKIP_LAST = 16 +} git_futils_mkdir_flags; + +/** + * Create a directory or entire path. + * + * This makes a directory (and the entire path leading up to it if requested), + * and optionally chmods the directory immediately after (or each part of the + * path if requested). + * + * @param path The path to create. + * @param base Root for relative path. These directories will never be made. + * @param mode The mode to use for created directories. + * @param flags Combination of the mkdir flags above. + * @return 0 on success, else error code + */ +extern int git_futils_mkdir(const char *path, const char *base, mode_t mode, uint32_t flags); /** * Create all the folders required to contain @@ -100,6 +130,47 @@ extern int git_futils_mktmp(git_buf *path_out, const char *filename); extern int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode); /** + * Copy a file, creating the destination path if needed. + * + * The filemode will be used for the file and the dirmode will be used for + * any intervening directories if necessary. + */ +extern int git_futils_cp_withpath( + const char *from, + const char *to, + mode_t filemode, + mode_t dirmode); + +/** + * Flags that can be passed to `git_futils_cp_r`. + */ +typedef enum { + GIT_CPDIR_CREATE_EMPTY_DIRS = 1, + GIT_CPDIR_COPY_SYMLINKS = 2, + GIT_CPDIR_COPY_DOTFILES = 4, + GIT_CPDIR_OVERWRITE = 8, + GIT_CPDIR_CHMOD = 16 +} git_futils_cpdir_flags; + +/** + * Copy a directory tree. + * + * This copies directories and files from one root to another. You can + * pass a combinationof GIT_CPDIR flags as defined above. + * + * If you pass the CHMOD flag, then the dirmode will be applied to all + * directories that are created during the copy, overiding the natural + * permissions. If you do not pass the CHMOD flag, then the dirmode + * will actually be copied from the source files and the `dirmode` arg + * will be ignored. + */ +extern int git_futils_cp_r( + const char *from, + const char *to, + uint32_t flags, + mode_t dirmode); + +/** * Open a file readonly and set error if needed. */ extern int git_futils_open_ro(const char *path); |