Skip to content

Commit fc27fe2

Browse files
author
Edward Thomson
committed
odb_loose: actually honor the fsync option
We've had an fsync option for a long time, but it was "ignored". Stop ignoring it.
1 parent fc77891 commit fc27fe2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

include/git2/odb_backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_
3939
* @param out location to store the odb backend pointer
4040
* @param objects_dir the Git repository's objects directory
4141
* @param compression_level zlib compression level to use
42-
* @param do_fsync whether to do an fsync() after writing (currently ignored)
42+
* @param do_fsync whether to do an fsync() after writing
4343
* @param dir_mode permissions to use creating a directory or 0 for defaults
4444
* @param file_mode permissions to use creating a file or 0 for defaults
4545
*

src/odb_loose.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,17 @@ static void loose_backend__stream_free(git_odb_stream *_stream)
838838
git__free(stream);
839839
}
840840

841+
static int filebuf_flags(loose_backend *backend)
842+
{
843+
int flags = GIT_FILEBUF_TEMPORARY |
844+
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT);
845+
846+
if (backend->fsync_object_files)
847+
flags |= GIT_FILEBUF_FSYNC;
848+
849+
return flags;
850+
}
851+
841852
static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend, git_off_t length, git_otype type)
842853
{
843854
loose_backend *backend;
@@ -864,9 +875,7 @@ static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_
864875
stream->stream.mode = GIT_STREAM_WRONLY;
865876

866877
if (git_buf_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 ||
867-
git_filebuf_open(&stream->fbuf, tmp_path.ptr,
868-
GIT_FILEBUF_TEMPORARY |
869-
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT),
878+
git_filebuf_open(&stream->fbuf, tmp_path.ptr, filebuf_flags(backend),
870879
backend->object_file_mode) < 0 ||
871880
stream->stream.write((git_odb_stream *)stream, hdr, hdrlen) < 0)
872881
{
@@ -894,9 +903,7 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c
894903
header_len = git_odb__format_object_header(header, sizeof(header), len, type);
895904

896905
if (git_buf_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 ||
897-
git_filebuf_open(&fbuf, final_path.ptr,
898-
GIT_FILEBUF_TEMPORARY |
899-
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT),
906+
git_filebuf_open(&fbuf, final_path.ptr, filebuf_flags(backend),
900907
backend->object_file_mode) < 0)
901908
{
902909
error = -1;

0 commit comments

Comments
 (0)