aboutsummaryrefslogtreecommitdiffstats
path: root/refs
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-03-25 16:38:24 -0700
committerJunio C Hamano <gitster@pobox.com>2022-03-25 16:38:25 -0700
commit6e1a8952e90e5d125177dbdee21425d1ba2d3584 (patch)
treecda2c48629c1e926d5b971954a038e79f0f0a325 /refs
parenteb804cd405618ef78b772072685c39392aea4ac1 (diff)
parentbc22d845c4328f5bd896d019b3729f776ad4be4c (diff)
downloadgit-6e1a8952e90e5d125177dbdee21425d1ba2d3584.tar.gz
Merge branch 'ps/fsync-refs'
Updates to refs traditionally weren't fsync'ed, but we can configure using core.fsync variable to do so. * ps/fsync-refs: core.fsync: new option to harden references
Diffstat (limited to 'refs')
-rw-r--r--refs/files-backend.c1
-rw-r--r--refs/packed-backend.c3
2 files changed, 3 insertions, 1 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0457ecdb42..bc81b52591 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1809,6 +1809,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
fd = get_lock_file_fd(&lock->lk);
if (write_in_full(fd, oid_to_hex(oid), the_hash_algo->hexsz) < 0 ||
write_in_full(fd, &term, 1) < 0 ||
+ fsync_component(FSYNC_COMPONENT_REFERENCE, get_lock_file_fd(&lock->lk)) < 0 ||
close_ref_gently(lock) < 0) {
strbuf_addf(err,
"couldn't write '%s'", get_lock_file_path(&lock->lk));
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index f56e2cc635..55a1426e67 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1262,7 +1262,8 @@ static int write_with_updates(struct packed_ref_store *refs,
goto error;
}
- if (close_tempfile_gently(refs->tempfile)) {
+ if (fsync_component(FSYNC_COMPONENT_REFERENCE, get_tempfile_fd(refs->tempfile)) ||
+ close_tempfile_gently(refs->tempfile)) {
strbuf_addf(err, "error closing file %s: %s",
get_tempfile_path(refs->tempfile),
strerror(errno));