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: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 71CFE203D3 for ; Mon, 28 Nov 2022 05:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1669613572; bh=D/EJmxF0/Fb4lS0WF+vPVePMJ0TDeYNM+WgyN37t7w4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EmHIQKyFE6/gehiro4N3bhkwrHfcIHApl245ksEhF2HHYuToTipSNtDeN8kS61T3L kGhDvgZRLnaVen6Yy2jofb2scrMcpk5IcJTFYGy8o49v2nWWDyyx2vyoO3jiuJIvt7 dx+g5aHPmQ22PhG+BFqMOHL+W8Ormboke0fY4A8k= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 92/95] lei_mirror: don't clobber inbox.config.example if it exists Date: Mon, 28 Nov 2022 05:32:29 +0000 Message-Id: <20221128053232.291618-93-e@80x24.org> In-Reply-To: <20221128053232.291618-1-e@80x24.org> References: <20221128053232.291618-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Users may save notes or edits in there, and it's only an example, so there's no need to mindlessly clobber it. --- lib/PublicInbox/LeiMirror.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index e284f55d..04e54955 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -181,13 +181,16 @@ sub _write_inbox_config { my $buf = delete($self->{'txt._/text/config/raw'}) // return; my $dst = $self->{cur_dst} // $self->{dst}; my $f = "$dst/inbox.config.example"; - open my $fh, '>', $f or die "open($f): $!"; - print $fh $buf or die "print: $!"; - chmod(0444 & ~umask, $fh) or die "chmod($f): $!"; my $mtime = delete $self->{'mtime._/text/config/raw'}; - $fh->flush or die "flush($f): $!"; - if (defined $mtime) { - utime($mtime, $mtime, $fh) or die "utime($f): $!"; + if (sysopen(my $fh, $f, O_CREAT|O_EXCL|O_WRONLY)) { + print $fh $buf or die "print: $!"; + chmod(0444 & ~umask, $fh) or die "chmod($f): $!"; + $fh->flush or die "flush($f): $!"; + if (defined $mtime) { + utime($mtime, $mtime, $fh) or die "utime($f): $!"; + } + } elsif (!$!{EEXIST}) { + die "open($f): $!"; } my $cfg = PublicInbox::Config->git_config_dump($f, $self->{lei}->{2}); my $ibx = $self->{ibx} = {};