Commit fc27fe21 by Edward Thomson

odb_loose: actually honor the fsync option

We've had an fsync option for a long time, but it was "ignored".
Stop ignoring it.
parent fc77891f
...@@ -39,7 +39,7 @@ GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_ ...@@ -39,7 +39,7 @@ GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_
* @param out location to store the odb backend pointer * @param out location to store the odb backend pointer
* @param objects_dir the Git repository's objects directory * @param objects_dir the Git repository's objects directory
* @param compression_level zlib compression level to use * @param compression_level zlib compression level to use
* @param do_fsync whether to do an fsync() after writing (currently ignored) * @param do_fsync whether to do an fsync() after writing
* @param dir_mode permissions to use creating a directory or 0 for defaults * @param dir_mode permissions to use creating a directory or 0 for defaults
* @param file_mode permissions to use creating a file or 0 for defaults * @param file_mode permissions to use creating a file or 0 for defaults
* *
......
...@@ -838,6 +838,17 @@ static void loose_backend__stream_free(git_odb_stream *_stream) ...@@ -838,6 +838,17 @@ static void loose_backend__stream_free(git_odb_stream *_stream)
git__free(stream); git__free(stream);
} }
static int filebuf_flags(loose_backend *backend)
{
int flags = GIT_FILEBUF_TEMPORARY |
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT);
if (backend->fsync_object_files)
flags |= GIT_FILEBUF_FSYNC;
return flags;
}
static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend, git_off_t length, git_otype type) static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend, git_off_t length, git_otype type)
{ {
loose_backend *backend; loose_backend *backend;
...@@ -864,9 +875,7 @@ static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_ ...@@ -864,9 +875,7 @@ static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_
stream->stream.mode = GIT_STREAM_WRONLY; stream->stream.mode = GIT_STREAM_WRONLY;
if (git_buf_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 || if (git_buf_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 ||
git_filebuf_open(&stream->fbuf, tmp_path.ptr, git_filebuf_open(&stream->fbuf, tmp_path.ptr, filebuf_flags(backend),
GIT_FILEBUF_TEMPORARY |
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT),
backend->object_file_mode) < 0 || backend->object_file_mode) < 0 ||
stream->stream.write((git_odb_stream *)stream, hdr, hdrlen) < 0) stream->stream.write((git_odb_stream *)stream, hdr, hdrlen) < 0)
{ {
...@@ -894,9 +903,7 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c ...@@ -894,9 +903,7 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c
header_len = git_odb__format_object_header(header, sizeof(header), len, type); header_len = git_odb__format_object_header(header, sizeof(header), len, type);
if (git_buf_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 || if (git_buf_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 ||
git_filebuf_open(&fbuf, final_path.ptr, git_filebuf_open(&fbuf, final_path.ptr, filebuf_flags(backend),
GIT_FILEBUF_TEMPORARY |
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT),
backend->object_file_mode) < 0) backend->object_file_mode) < 0)
{ {
error = -1; error = -1;
......
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