From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id 4220F1F403 for ; Fri, 21 Oct 2022 23:24:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbiJUXYx (ORCPT ); Fri, 21 Oct 2022 19:24:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbiJUXYw (ORCPT ); Fri, 21 Oct 2022 19:24:52 -0400 Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38759543C1 for ; Fri, 21 Oct 2022 16:24:47 -0700 (PDT) Received: (qmail 14838 invoked by uid 109); 21 Oct 2022 23:24:47 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Fri, 21 Oct 2022 23:24:47 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 18016 invoked by uid 111); 21 Oct 2022 23:24:48 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Fri, 21 Oct 2022 19:24:48 -0400 Authentication-Results: peff.net; auth=none Date: Fri, 21 Oct 2022 19:24:46 -0400 From: Jeff King To: Junio C Hamano Cc: git@vger.kernel.org, Jan =?utf-8?Q?Pokorn=C3=BD?= , Taylor Blau Subject: Re: [PATCH 3/4] repack: use tempfiles for signal cleanup Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Fri, Oct 21, 2022 at 03:30:29PM -0700, Junio C Hamano wrote: > > @@ -867,8 +860,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix) > > split_pack_geometry(geometry, geometric_factor); > > } > > > > - sigchain_push_common(remove_pack_on_signal); > > - > > prepare_pack_objects(&cmd, &po_args); > > > > show_progress = !po_args.quiet && isatty(2); > > @@ -1020,14 +1011,14 @@ int cmd_repack(int argc, const char **argv, const char *prefix) > > fname_old = mkpathdup("%s-%s%s", > > packtmp, item->string, exts[ext].name); > > > > - if (data->exts[ext]) { > > + if (data->tempfiles[ext]) { > > struct stat statbuffer; > > if (!stat(fname_old, &statbuffer)) { > > statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); > > chmod(fname_old, statbuffer.st_mode); > > } > > > > - if (rename(fname_old, fname)) > > + if (rename_tempfile(&data->tempfiles[ext], fname)) > > die_errno(_("renaming '%s' failed"), fname_old); > > It now got a bit confusing that we have 'fname', 'fname_old', and > the tempfile. The path.buf used as the argument to register_tempfile() > matches what is used to compute fname_old above. I wonder if tempfile > API does not give us that name so that we can stop using fname_old here? It does, and we probably should use get_tempfile_path() in the error message here. But sadly we can't get rid of fname_old entirely, as it's used below this for the second block in the if-else chain: if (data->tempfiles[ext]) { ...do the rename ... } else if (!exts[ext].optional) die(_("missing required file: %s"), fname_old); else if (unlink(fname) < 0 && errno != ENOENT) die_errno(_("could not unlink: %s"), fname); OTOH, it would probably be equally readable (or perhaps even better) for that second block to say: die("pack-objects did not generate a '%s' file for pack %s", exts[ext].name, item->string); And then we could drop fname_old entirely. Which is nice, because it gets rid of the implicit assumption that the tempfile matches what is in fname_old (which is always true, but since they are generated by individual lines far apart from each other, it's possible for that to change). -Peff