about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-31 13:51:40 +0000
committerEric Wong <e@80x24.org>2021-01-01 05:00:39 +0000
commitfee0f2529ece728f59330c8d01d624d32f9eca06 (patch)
treea68cbccae91f601a0012f42f3278c8e41ee097fb /lib
parent5bbcd1686c10985168b98046d3edc6cf0818df8c (diff)
downloadpublic-inbox-fee0f2529ece728f59330c8d01d624d32f9eca06.tar.gz
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).
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/LeiToMail.pm9
1 files 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;