]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_mirror: don't clobber inbox.config.example if it exists
authorEric Wong <e@80x24.org>
Mon, 28 Nov 2022 05:32:29 +0000 (05:32 +0000)
committerEric Wong <e@80x24.org>
Mon, 28 Nov 2022 23:39:00 +0000 (23:39 +0000)
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

index e284f55deb6133cb25eaaf0113426ff7517434d6..04e5495561e1533b18e25835c46ddec77ebc689f 100644 (file)
@@ -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} = {};