summaryrefslogtreecommitdiff
path: root/src/indexer.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2017-02-28 12:29:29 +0000
committerEdward Thomson <ethomson@github.com>2017-03-02 09:11:33 +0000
commit1c04a96b25da048221f31ecee0227d960dc00489 (patch)
tree14774879d60dec45b5610cb7ed1bae927ef2016f /src/indexer.c
parent3ac05d11493d0573dbf725a19403dbf5e8d93b50 (diff)
downloadlibgit2-1c04a96b25da048221f31ecee0227d960dc00489.tar.gz
Honor `core.fsyncObjectFiles`ethomson/fsync
Diffstat (limited to 'src/indexer.c')
-rw-r--r--src/indexer.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/indexer.c b/src/indexer.c
index 3fd7223e5..ce67240ce 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -34,7 +34,8 @@ struct git_indexer {
unsigned int parsed_header :1,
pack_committed :1,
have_stream :1,
- have_delta :1;
+ have_delta :1,
+ do_fsync :1;
struct git_pack_header hdr;
struct git_pack_file *pack;
unsigned int mode;
@@ -124,6 +125,9 @@ int git_indexer_new(
git_hash_ctx_init(&idx->hash_ctx);
git_hash_ctx_init(&idx->trailer);
+ if (git_object__synchronous_writing)
+ idx->do_fsync = 1;
+
error = git_buf_joinpath(&path, prefix, suff);
if (error < 0)
goto cleanup;
@@ -162,6 +166,11 @@ cleanup:
return -1;
}
+void git_indexer__set_fsync(git_indexer *idx, int do_fsync)
+{
+ idx->do_fsync = !!do_fsync;
+}
+
/* Try to store the delta so we can try to resolve it later */
static int store_delta(git_indexer *idx)
{
@@ -991,7 +1000,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
if (git_filebuf_open(&index_file, filename.ptr,
GIT_FILEBUF_HASH_CONTENTS |
- (git_object__synchronous_writing ? GIT_FILEBUF_FSYNC : 0),
+ (idx->do_fsync ? GIT_FILEBUF_FSYNC : 0),
idx->mode) < 0)
goto on_error;
@@ -1069,7 +1078,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
return -1;
}
- if (git_object__synchronous_writing && p_fsync(idx->pack->mwf.fd) < 0) {
+ if (idx->do_fsync && p_fsync(idx->pack->mwf.fd) < 0) {
giterr_set(GITERR_OS, "failed to fsync packfile");
goto on_error;
}
@@ -1090,7 +1099,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
goto on_error;
/* And fsync the parent directory if we're asked to. */
- if (git_object__synchronous_writing &&
+ if (idx->do_fsync &&
git_futils_fsync_parent(git_buf_cstr(&filename)) < 0)
goto on_error;