Skip to content

Commit c472db5

Browse files
avargitster
authored andcommitted
object-file.c: do fsync() and close() before post-write die()
Change write_loose_object() to do an fsync() and close() before the oideq() sanity check at the end. This change re-joins code that was split up by the die() sanity check added in 748af44 (sha1_file: be paranoid when creating loose objects, 2010-02-21). I don't think that this change matters in itself, if we called die() it was possible that our data wouldn't fully make it to disk, but in any case we were writing data that we'd consider corrupted. It's possible that a subsequent "git fsck" will be less confused now. The real reason to make this change is that in a subsequent commit we'll split this code in write_loose_object() into a utility function, all its callers will want the preceding sanity checks, but not the "oideq" check. By moving the close_loose_object() earlier it'll be easier to reason about the introduction of the utility function. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c3dddb4 commit c472db5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

object-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,12 +2012,12 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
20122012
die(_("deflateEnd on object %s failed (%d)"), oid_to_hex(oid),
20132013
ret);
20142014
the_hash_algo->final_oid_fn(&parano_oid, &c);
2015+
close_loose_object(fd, tmp_file.buf);
2016+
20152017
if (!oideq(oid, &parano_oid))
20162018
die(_("confused by unstable object source data for %s"),
20172019
oid_to_hex(oid));
20182020

2019-
close_loose_object(fd, tmp_file.buf);
2020-
20212021
if (mtime) {
20222022
struct utimbuf utb;
20232023
utb.actime = mtime;

0 commit comments

Comments
 (0)