summaryrefslogtreecommitdiff
path: root/src/fileops.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/fileops.h')
-rw-r--r--src/fileops.h83
1 files changed, 77 insertions, 6 deletions
diff --git a/src/fileops.h b/src/fileops.h
index edfcb7dd..6f345037 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);