All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: Re: [PATCH 2/4] reftable/stack: register new tables as tempfiles
Date: Wed, 6 Mar 2024 12:59:59 +0100	[thread overview]
Message-ID: <Zehav4V_8GGZG94Q@tanuki> (raw)
In-Reply-To: <6cw6d3ubo2kbogzdbniyoznij2zfoh5t3htwb4oaghaltcgeqg@kkrw4g6atr2k>

[-- Attachment #1: Type: text/plain, Size: 2409 bytes --]

On Tue, Mar 05, 2024 at 04:30:18PM -0600, Justin Tobler wrote:
> On 24/03/04 12:10PM, Patrick Steinhardt wrote:
> > We do not register new tables which we're about to add to the stack with
> > the tempfile API. Those tables will thus not be deleted in case Git gets
> > killed.
> > 
> > Refactor the code to register tables as tempfiles.
> > 
> > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > ---
> >  reftable/stack.c | 29 ++++++++++++-----------------
> >  1 file changed, 12 insertions(+), 17 deletions(-)
> > 
> > diff --git a/reftable/stack.c b/reftable/stack.c
> > index b64e55648a..81544fbfa0 100644
> > --- a/reftable/stack.c
> > +++ b/reftable/stack.c
> > @@ -737,8 +737,9 @@ int reftable_addition_add(struct reftable_addition *add,
> >  	struct strbuf tab_file_name = STRBUF_INIT;
> >  	struct strbuf next_name = STRBUF_INIT;
> >  	struct reftable_writer *wr = NULL;
> > +	struct tempfile *tab_file = NULL;
> >  	int err = 0;
> > -	int tab_fd = 0;
> > +	int tab_fd;
> >  
> >  	strbuf_reset(&next_name);
> >  	format_name(&next_name, add->next_update_index, add->next_update_index);
> > @@ -746,17 +747,20 @@ int reftable_addition_add(struct reftable_addition *add,
> >  	stack_filename(&temp_tab_file_name, add->stack, next_name.buf);
> >  	strbuf_addstr(&temp_tab_file_name, ".temp.XXXXXX");
> >  
> > -	tab_fd = mkstemp(temp_tab_file_name.buf);
> > -	if (tab_fd < 0) {
> > +	tab_file = mks_tempfile(temp_tab_file_name.buf);
> > +	if (!tab_file) {
> >  		err = REFTABLE_IO_ERROR;
> >  		goto done;
> >  	}
> >  	if (add->stack->config.default_permissions) {
> > -		if (chmod(temp_tab_file_name.buf, add->stack->config.default_permissions)) {
> > +		if (chmod(get_tempfile_path(tab_file),
> > +			  add->stack->config.default_permissions)) {
> >  			err = REFTABLE_IO_ERROR;
> >  			goto done;
> >  		}
> >  	}
> 
> Since the tempfile is now being created through the tempfile API, I
> think the file mode can be set directly through `mks_tempfile_m()`
> instead of creating the tempfile and then using chmod. Just something I
> thought to mention.

Unfortunately not. The problem is that `mks_tempfile_m()` will munge
passed-in permissions via "core.sharedRepository", but we already pre
calculated the target mode in `config.default_permissions`. Thus, the
result would have wrong permissions if we used `mks_tempfile_m()`.

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-03-06 12:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 11:10 [PATCH 0/4] reftable/stack: register temporary files Patrick Steinhardt
2024-03-04 11:10 ` [PATCH 1/4] lockfile: report when rollback fails Patrick Steinhardt
2024-03-05 22:09   ` Justin Tobler
2024-03-06 12:00     ` Patrick Steinhardt
2024-03-04 11:10 ` [PATCH 2/4] reftable/stack: register new tables as tempfiles Patrick Steinhardt
2024-03-05 22:30   ` Justin Tobler
2024-03-06 11:59     ` Patrick Steinhardt [this message]
2024-03-06 16:34       ` Justin Tobler
2024-03-06 16:36       ` Junio C Hamano
2024-03-07  6:17         ` Patrick Steinhardt
2024-03-07 17:59           ` Junio C Hamano
2024-03-07 20:54             ` Patrick Steinhardt
2024-03-07 21:06               ` Junio C Hamano
2024-03-04 11:10 ` [PATCH 3/4] reftable/stack: register lockfiles during compaction Patrick Steinhardt
2024-03-05 23:30   ` Justin Tobler
2024-03-06 11:59     ` Patrick Steinhardt
2024-03-06 16:39       ` Junio C Hamano
2024-03-06 19:57       ` Justin Tobler
2024-03-04 11:10 ` [PATCH 4/4] reftable/stack: register compacted tables as tempfiles Patrick Steinhardt
2024-03-07 12:38   ` Toon claes
2024-03-07 12:58     ` Patrick Steinhardt
2024-03-07 13:10 ` [PATCH v2 0/4] reftable/stack: register temporary files Patrick Steinhardt
2024-03-07 13:10   ` [PATCH v2 1/4] lockfile: report when rollback fails Patrick Steinhardt
2024-03-07 13:10   ` [PATCH v2 2/4] reftable/stack: register new tables as tempfiles Patrick Steinhardt
2024-03-07 13:10   ` [PATCH v2 3/4] reftable/stack: register lockfiles during compaction Patrick Steinhardt
2024-03-07 13:10   ` [PATCH v2 4/4] reftable/stack: register compacted tables as tempfiles Patrick Steinhardt

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=Zehav4V_8GGZG94Q@tanuki \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    /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.