git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/4] midx.c: guard against commit_lock_file() failures

From
Taylor Blau <me@ttaylorr.com>
Date
Oct 8, 2021, 21:46 UTC
Message-ID
<ed7407cefa89b973d1085973f4ddb39397597036.1633729502.git.me@ttaylorr.com>
In-Reply-To
<cover.1633729502.git.me@ttaylorr.com>

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>
---
 midx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/midx.c b/midx.c
index 137af3fc67..e79fb4427d 100644
--- a/midx.c
+++ b/midx.c
@@ -1434,7 +1434,8 @@ static int write_midx_internal(const char *object_dir,
 	if (ctx.m)
 		close_object_store(the_repository->objects);
 
-	commit_lock_file(&lk);
+	if (commit_lock_file(&lk) < 0)
+		die_errno(_("could not write multi-pack-index"));
 
 	clear_midx_files_ext(object_dir, ".bitmap", midx_hash);
 	clear_midx_files_ext(object_dir, ".rev", midx_hash);
-- 
2.33.0.96.g73915697e6
Previous: Taylor BlauNext: Ævar Arnfjörð Bjarmason
Message 6 of 8 in “midx: avoid potential rename-while-mapped on Windows”
  1. 0/4 midx: avoid potential rename-while-mapped on WindowsTaylor Blau, Oct 8, 2021
  2. 1/4 midx.c: extract MIDX lookup by object_dirTaylor Blau, Oct 8, 2021
  3. 2/4 midx.c: lookup MIDX by object directory during expireTaylor Blau, Oct 8, 2021
  4. Derrick StoleeOct 13, 2021
  5. 3/4 midx.c: lookup MIDX by object directory during repackTaylor Blau, Oct 8, 2021
  6. 4/4 midx.c: guard against commit_lock_file() failuresTaylor Blau, Oct 8, 2021
  7. Ævar Arnfjörð BjarmasonOct 9, 2021
  8. Derrick StoleeOct 13, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.