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

[PATCH 3/5] midx: don't peek into `struct lock_file`

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Jan 5, 2021, 19:23 UTC
Message-ID
<6dfb457b2a3187546eb4b4d90679348f2051a57d.1609874026.git.martin.agren@gmail.com>
In-Reply-To
<cover.1609874026.git.martin.agren@gmail.com>

Similar to the previous commits, avoid peeking into the `struct lock_file`. Use the lock file API instead.

The two functions we're calling here double-check that the tempfile is indeed "active", which is arguably overkill considering how we took the lock on the line immediately above. More importantly, this future-proofs us against, e.g., other code appearing between these two lines or the lock file and/or tempfile internals changing.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 midx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/midx.c b/midx.c
index 79c282b070..9d41b9c271 100644
--- a/midx.c
+++ b/midx.c
@@ -918,7 +918,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
 					(pack_name_concat_len % MIDX_CHUNK_ALIGNMENT);
 
 	hold_lock_file_for_update(&lk, midx_name, LOCK_DIE_ON_ERROR);
-	f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
+	f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk));
 	FREE_AND_NULL(midx_name);
 
 	if (packs.m)
-- 
2.30.0
Previous: Martin ÅgrenNext: Martin Ågren
Message 3 of 13 in “avoid peeking into `struct lock_file`”
  1. 0/5 avoid peeking into `struct lock_file`Martin Ågren, Jan 5, 2021
  2. 4/5 refs/files-backend: don't peek into `struct lock_file`Martin Ågren, Jan 5, 2021
  3. 3/5 midx: don't peek into `struct lock_file`Martin Ågren, Jan 5, 2021
  4. 2/5 commit-graph: don't peek into `struct lock_file`Martin Ågren, Jan 5, 2021
  5. 1/5 builtin/gc: don't peek into `struct lock_file`Martin Ågren, Jan 5, 2021
  6. 5/5 read-cache: try not to peek into `struct {lock_,temp}file`Martin Ågren, Jan 5, 2021
  7. Derrick StoleeJan 6, 2021
  8. Junio C HamanoJan 6, 2021
  9. Junio C HamanoJan 6, 2021
  10. Derrick StoleeJan 7, 2021
  11. Martin ÅgrenJan 7, 2021
  12. Junio C HamanoJan 7, 2021
  13. Martin ÅgrenJan 7, 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.