All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Taylor Blau <me@ttaylorr.com>
Cc: git@vger.kernel.org,  Jeff King <peff@peff.net>,
	 Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 2/2] server-info.c: remove temporary info files on exit
Date: Fri, 07 Jun 2024 09:02:14 -0700	[thread overview]
Message-ID: <xmqqfrtog2rd.fsf@gitster.g> (raw)
In-Reply-To: <2d5a0536af1a6d45835622e2c020266079fa0873.1717712358.git.me@ttaylorr.com> (Taylor Blau's message of "Thu, 6 Jun 2024 18:19:31 -0400")

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.

>  	if (uic_is_stale(&uic)) {
> -		if (adjust_shared_perm(tmp) < 0)
> +		if (adjust_shared_perm(get_tempfile_path(f)) < 0)
>  			goto out;
> -		if (rename(tmp, path) < 0)
> +		if (rename_tempfile(&f, path) < 0)
>  			goto out;
>  	} else {
> -		unlink(tmp);
> +		delete_tempfile(&f);
>  	}
>  	ret = 0;
>  
>  out:
>  	if (ret) {
>  		error_errno("unable to update %s", path);
> -		if (uic.cur_fp)
> -			fclose(uic.cur_fp);
> -		else if (fd >= 0)
> -			close(fd);
> -		unlink(tmp);
> +		if (f)
> +			delete_tempfile(&f);
>  	}
>  	free(tmp);
>  	if (uic.old_fp)

  reply	other threads:[~2024-06-07 16:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-06 22:19 [PATCH 0/2] commit-graph/server-info: use tempfile.h in more places Taylor Blau
2024-06-06 22:19 ` [PATCH 1/2] commit-graph.c: remove temporary graph layers on exit Taylor Blau
2024-06-07 16:33   ` Junio C Hamano
2024-06-07 21:41     ` Taylor Blau
2024-06-07 21:47       ` Junio C Hamano
2024-06-08  9:42         ` Jeff King
2024-06-07 21:49       ` Junio C Hamano
2024-06-08  9:53   ` Jeff King
2024-06-06 22:19 ` [PATCH 2/2] server-info.c: remove temporary info files " Taylor Blau
2024-06-07 16:02   ` Junio C Hamano [this message]
2024-06-07 21:44     ` Taylor Blau
2024-06-07 21:49       ` Junio C Hamano
2024-06-08 10:25   ` Jeff King
2024-06-07 15:40 ` [PATCH 0/2] commit-graph/server-info: use tempfile.h in more places Junio C Hamano
2024-06-08 10:48 ` Jeff King
2024-06-14 17:41   ` Elijah Newren
2024-06-14 19:35   ` Taylor Blau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqfrtog2rd.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    --cc=newren@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.