#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);
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`.
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.
*
* 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
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`.
*
* 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;
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__ */