]> git.proxmox.com Git - libgit2.git/blobdiff - src/fileops.h
treebuilder: fix memory leaks in `write_with_buffer`
[libgit2.git] / src / fileops.h
index 4aaf1781c360421022348b52881198bfb78e0c40..46886b0d7729e5e8b32d264d924f045260020532 100644 (file)
@@ -11,6 +11,9 @@
 #include "map.h"
 #include "posix.h"
 #include "path.h"
+#include "pool.h"
+#include "strmap.h"
+#include "oid.h"
 
 /**
  * Filebuffer methods
  */
 extern int git_futils_readbuffer(git_buf *obj, const char *path);
 extern int git_futils_readbuffer_updated(
-       git_buf *obj, const char *path, time_t *mtime, size_t *size, int *updated);
+       git_buf *obj, const char *path, git_oid *checksum, int *updated);
 extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
 
+/* Additional constants for `git_futils_writebuffer`'s `open_flags`.  We
+ * support these internally and they will be removed before the `open` call.
+ */
+#ifndef O_FSYNC
+# define O_FSYNC (1 << 31)
+#endif
+
 extern int git_futils_writebuffer(
        const git_buf *buf, const char *path, int open_flags, mode_t mode);
 
@@ -42,23 +52,20 @@ extern int git_futils_writebuffer(
 extern int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode);
 
 /**
- * Create an open a process-locked file
+ * Create and open a process-locked file
  */
 extern int git_futils_creat_locked(const char *path, const mode_t mode);
 
 /**
- * Create an open a process-locked file, while
+ * Create and open a process-locked file, while
  * also creating all the folders in its path
  */
 extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode);
 
 /**
- * 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.
+ * Create a path recursively.
  */
-extern int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode);
+extern int git_futils_mkdir_r(const char *path, const mode_t mode);
 
 /**
  * Flags to pass to `git_futils_mkdir`.
@@ -95,6 +102,13 @@ struct git_futils_mkdir_perfdata
        size_t chmod_calls;
 };
 
+struct git_futils_mkdir_options
+{
+       git_strmap *dir_map;
+       git_pool *pool;
+       struct git_futils_mkdir_perfdata perfdata;
+};
+
 /**
  * Create a directory or entire path.
  *
@@ -102,20 +116,20 @@ struct git_futils_mkdir_perfdata
  * and optionally chmods the directory immediately after (or each part of the
  * path if requested).
  *
- * @param path The path to create.
+ * @param path The path to create, relative to base.
  * @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.
- * @param perfdata Performance data, use `git_futils_mkdir` if you don't want this data.
+ * @param opts Extended options, or null.
  * @return 0 on success, else error code
  */
-extern int git_futils_mkdir_withperf(const char *path, const char *base, mode_t mode, uint32_t flags, struct git_futils_mkdir_perfdata *perfdata);
+extern int git_futils_mkdir_relative(const char *path, const char *base, mode_t mode, uint32_t flags, struct git_futils_mkdir_options *opts);
 
 /**
- * Create a directory or entire path.  Similar to `git_futils_mkdir_withperf`
+ * Create a directory or entire path.  Similar to `git_futils_mkdir_relative`
  * without performance data.
  */
-extern int git_futils_mkdir(const char *path, const char *base, mode_t mode, uint32_t flags);
+extern int git_futils_mkdir(const char *path, mode_t mode, uint32_t flags);
 
 /**
  * Create all the folders required to contain
@@ -177,6 +191,12 @@ extern int git_futils_cp(
        const char *to,
        mode_t filemode);
 
+/**
+ * Set the files atime and mtime to the given time, or the current time
+ * if `ts` is NULL.
+ */
+extern int git_futils_touch(const char *path, time_t *when);
+
 /**
  * Flags that can be passed to `git_futils_cp_r`.
  *
@@ -303,7 +323,7 @@ extern int git_futils_fake_symlink(const char *new, const char *old);
  * versions could be implemented in the future.
  */
 typedef struct {
-       git_time_t mtime;
+       struct timespec mtime;
        git_off_t  size;
        unsigned int ino;
 } git_futils_filestamp;
@@ -343,4 +363,22 @@ extern void git_futils_filestamp_set(
 extern void git_futils_filestamp_set_from_stat(
        git_futils_filestamp *stamp, struct stat *st);
 
+/**
+ * `fsync` the parent directory of the given path, if `fsync` is
+ * supported for directories on this platform.
+ *
+ * @param path Path of the directory to sync.
+ * @return 0 on success, -1 on error
+ */
+extern int git_futils_fsync_dir(const char *path);
+
+/**
+ * `fsync` the parent directory of the given path, if `fsync` is
+ * supported for directories on this platform.
+ *
+ * @param path Path of the file whose parent directory should be synced.
+ * @return 0 on success, -1 on error
+ */
+extern int git_futils_fsync_parent(const char *path);
+
 #endif /* INCLUDE_fileops_h__ */