diff options
author | Edward Thomson <ethomson@github.com> | 2016-12-15 14:49:43 -0600 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2017-02-28 13:28:36 +0000 |
commit | eb56ed81afd0091a0616a1099d7792f12e0726f6 (patch) | |
tree | 03b958ff1b7d2f6dc51ba1eb40fc0949e387aba5 | |
parent | af3dcb0e50416ce08bcfed7524b073b980180ef2 (diff) | |
download | libgit2-eb56ed81afd0091a0616a1099d7792f12e0726f6.tar.gz |
refdb_fs: optionally fsync packed refs
-rw-r--r-- | src/refdb_fs.c | 7 | ||||
-rw-r--r-- | tests/refs/create.c | 15 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 11ff96843..fac5ba5d1 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -994,15 +994,18 @@ static int packed_write(refdb_fs_backend *backend) { git_sortedcache *refcache = backend->refcache; git_filebuf pack_file = GIT_FILEBUF_INIT; - int error; + int error, open_flags = 0; size_t i; /* lock the cache to updates while we do this */ if ((error = git_sortedcache_wlock(refcache)) < 0) return error; + if (git_object__synchronized_writing) + open_flags = GIT_FILEBUF_FSYNC; + /* Open the file! */ - if ((error = git_filebuf_open(&pack_file, git_sortedcache_path(refcache), 0, GIT_PACKEDREFS_FILE_MODE)) < 0) + if ((error = git_filebuf_open(&pack_file, git_sortedcache_path(refcache), open_flags, GIT_PACKEDREFS_FILE_MODE)) < 0) goto fail; /* Packfiles have a header... apparently diff --git a/tests/refs/create.c b/tests/refs/create.c index 1189c47f3..5c46fb3c2 100644 --- a/tests/refs/create.c +++ b/tests/refs/create.c @@ -303,17 +303,24 @@ void test_refs_create__creating_a_loose_ref_with_invalid_windows_name(void) void test_refs_create__does_not_fsync_by_default(void) { git_reference *ref = NULL; + git_refdb *refdb; git_oid id; git_oid_fromstr(&id, current_master_tip); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/fsync_test", &id, 0, "log message")); git_reference_free(ref); + + cl_git_pass(git_repository_refdb(&refdb, g_repo)); + cl_git_pass(git_refdb_compress(refdb)); + git_refdb_free(refdb); + cl_assert_equal_i(0, p_fsync__cnt); } void test_refs_create__fsyncs_when_requested(void) { git_reference *ref = NULL; + git_refdb *refdb; git_oid id; cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION, 1)); @@ -323,4 +330,12 @@ void test_refs_create__fsyncs_when_requested(void) cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/fsync_test", &id, 0, "log message")); git_reference_free(ref); cl_assert_equal_i(2, p_fsync__cnt); + + p_fsync__cnt = 0; + + cl_git_pass(git_repository_refdb(&refdb, g_repo)); + cl_git_pass(git_refdb_compress(refdb)); + git_refdb_free(refdb); + + cl_assert_equal_i(1, p_fsync__cnt); } |