diff options
author | Edward Thomson <ethomson@github.com> | 2016-12-13 10:07:42 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2017-02-28 13:27:49 +0000 |
commit | fc77891f6308ee4ca837cdf558969c5c457b1392 (patch) | |
tree | 08c6e631674fab973d73a91a9286ef96bfb0a8a4 | |
parent | a4b5ac643c46ed1cf26dac52fd41f86a09b679dd (diff) | |
download | libgit2-fc77891f6308ee4ca837cdf558969c5c457b1392.tar.gz |
git_filebuf: optionally fsync when committing
-rw-r--r-- | src/filebuf.c | 8 | ||||
-rw-r--r-- | src/filebuf.h | 4 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/filebuf.c b/src/filebuf.c index ef68b16f4..c4a13ffab 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -291,6 +291,9 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo if (flags & GIT_FILEBUF_DO_NOT_BUFFER) file->do_not_buffer = true; + if (flags & GIT_FILEBUF_FSYNC) + file->do_fsync = true; + file->buf_size = size; file->buf_pos = 0; file->fd = -1; @@ -425,6 +428,11 @@ int git_filebuf_commit(git_filebuf *file) file->fd_is_open = false; + if (file->do_fsync && p_fsync(file->fd) < 0) { + giterr_set(GITERR_OS, "failed to fsync '%s'", file->path_lock); + goto on_error; + } + if (p_close(file->fd) < 0) { giterr_set(GITERR_OS, "failed to close file at '%s'", file->path_lock); goto on_error; diff --git a/src/filebuf.h b/src/filebuf.h index 467708d45..c65aea780 100644 --- a/src/filebuf.h +++ b/src/filebuf.h @@ -20,7 +20,8 @@ #define GIT_FILEBUF_FORCE (1 << 3) #define GIT_FILEBUF_TEMPORARY (1 << 4) #define GIT_FILEBUF_DO_NOT_BUFFER (1 << 5) -#define GIT_FILEBUF_DEFLATE_SHIFT (6) +#define GIT_FILEBUF_FSYNC (1 << 6) +#define GIT_FILEBUF_DEFLATE_SHIFT (7) #define GIT_FILELOCK_EXTENSION ".lock\0" #define GIT_FILELOCK_EXTLENGTH 6 @@ -47,6 +48,7 @@ struct git_filebuf { bool created_lock; bool did_rename; bool do_not_buffer; + bool do_fsync; int last_error; }; |