midx.c: guard against commit_lock_file() failures

When writing a MIDX, we atomically move the new MIDX into place via commit_lock_file(), but do not check to see if that call was successful. Make sure that we do check in order to prevent us from incorrectly reporting that we wrote a new MIDX if we actually encountered an error. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Oct 8, 2021 at 17:46 UTC ae22e8415d5ec2b52a4c83e181297ac15aeaced0
1 file changed +2 -1
midx.c
+2 -1
@@ -1423,7 +1423,8 @@ static int write_midx_internal(const char *object_dir,
1423 if (ctx.m)
1424 close_object_store(the_repository->objects);
1425
1426 - commit_lock_file(&lk);
1426 + if (commit_lock_file(&lk) < 0)
1427 + die_errno(_("could not write multi-pack-index"));
1428
1429 clear_midx_files_ext(object_dir, ".bitmap", midx_hash);
1430 clear_midx_files_ext(object_dir, ".rev", midx_hash);