Commit eb56ed81 by Edward Thomson

refdb_fs: optionally fsync packed refs

parent af3dcb0e
......@@ -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
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment