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

Re: [PATCH 2/2] server-info.c: remove temporary info files on exit

From
Taylor Blau <me@ttaylorr.com>
Date
Jun 7, 2024, 21:44 UTC
Message-ID
<ZmN/NZlriT3gsw7p@nand.local>
In-Reply-To
<xmqqfrtog2rd.fsf@gitster.g>
On Fri, Jun 07, 2024 at 09:02:14AM -0700, Junio C Hamano wrote:
Show 20 quoted lines
> Taylor Blau <me@ttaylorr.com> writes:
>
> > @@ -121,27 +120,22 @@ static int update_info_file(char *path,
> >  	}
> >
> >  	uic.cur_fp = NULL;
> > -	if (fclose(to_close))
> > -		goto out;
>
> We should fflush() of cur_fp before nuking it, at least, no?
>
> In the original code, to_close was a mere copy of uic.cur_fp and we
> made sure that anything buffered at the stdio layer are flushed to
> the underlying file desciptor (fd that we obtained from
> git_mkstemp_mode() in the original code) with this fclose() call.
>
> We no longer do so.  We later call rename_tempfile() to close the
> underlying file descriptor and move the temporary file to its final
> place, but I do not see what guarantee we have that we do not lose
> what we had buffered in the stdio with the updated code.

rename_tempfile() first calls close_tempfile_gently() before calling rename(). close_tempfile_gently() calls fclose() on temp->fp before returns, so we get our fflush() call implicitly there.

IOW, the tempfile.h API is happy for us to call rename_tempfile() without having explicitly closed or flushed the underlying file pointer.

Thanks, Taylor

Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 17 in “commit-graph/server-info: use tempfile.h in more places”
  1. 0/2 commit-graph/server-info: use tempfile.h in more placesTaylor Blau, Jun 6, 2024
  2. 1/2 commit-graph.c: remove temporary graph layers on exitTaylor Blau, Jun 6, 2024
  3. Junio C HamanoJun 7, 2024
  4. Taylor BlauJun 7, 2024
  5. Junio C HamanoJun 7, 2024
  6. Jeff KingJun 8, 2024
  7. Junio C HamanoJun 7, 2024
  8. Jeff KingJun 8, 2024
  9. 2/2 server-info.c: remove temporary info files on exitTaylor Blau, Jun 6, 2024
  10. Junio C HamanoJun 7, 2024
  11. Taylor BlauJun 7, 2024
  12. Junio C HamanoJun 7, 2024
  13. Jeff KingJun 8, 2024
  14. Junio C HamanoJun 7, 2024
  15. Jeff KingJun 8, 2024
  16. Elijah NewrenJun 14, 2024
  17. Taylor BlauJun 14, 2024

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.