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-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 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 0B9C91FFAC for ; Thu, 31 Dec 2020 13:51:57 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 22/36] lei_to_mail: unlink mboxes if not augmenting Date: Thu, 31 Dec 2020 13:51:40 +0000 Message-Id: <20201231135154.6070-23-e@80x24.org> In-Reply-To: <20201231135154.6070-1-e@80x24.org> References: <20201231135154.6070-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This matches mairix(1) behavior and may be safer if there's concurrent readers on the existing mbox, especially since we don't do currently implement mbox locking (nor does mairix). --- lib/PublicInbox/LeiToMail.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm index 0b2685b0..5b80eb27 100644 --- a/lib/PublicInbox/LeiToMail.pm +++ b/lib/PublicInbox/LeiToMail.pm @@ -13,7 +13,7 @@ use PublicInbox::LeiDedupe; use Symbol qw(gensym); use IO::Handle; # ->autoflush use Fcntl qw(SEEK_SET SEEK_END O_CREAT O_EXCL O_WRONLY); -use Errno qw(EEXIST ESPIPE); +use Errno qw(EEXIST ESPIPE ENOENT); my %kw2char = ( # Maildir characters draft => 'D', @@ -230,7 +230,10 @@ sub _mbox_write_cb ($$$$) { # XXX should we support /dev/stdout.gz ? if ($dst eq '/dev/stdout') { $out = $lei->{1}; - } else { # TODO: mbox locking + } else { # TODO: mbox locking (but mairix doesn't...) + if (!$lei->{opt}->{augment} && -f $dst and !unlink($dst)) { + die "unlink $dst: $!" if $! != ENOENT; + } open $out, '+>>', $dst or die "open $dst: $!"; # Perl does SEEK_END even with O_APPEND :< $seekable = seek($out, 0, SEEK_SET); @@ -251,8 +254,6 @@ sub _mbox_write_cb ($$$$) { # maybe some systems don't honor O_APPEND, Perl does this: seek($out, 0, SEEK_END) or die "seek $dst: $!"; $dedupe->pause_dedupe if $jobs; # are we forking? - } elsif ($seekable) { - truncate($out, 0) or die "truncate $dst: $!"; } $dedupe->prepare_dedupe if !$jobs; ($out, $pipe_lk) = compress_dst($out, $zsfx, $lei) if $zsfx;