X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FEmergency.pm;h=67f27bc7f18877a127220b400f1a19507c48872d;hb=af0b0fb7a454470a32c452119d0392e0dedb3fe1;hp=4ee862153fdfe3d80d4735b68b7d0e32a5cd43cd;hpb=f7db02b9aec08b37e08893e6e96c07725a0c1620;p=public-inbox.git
diff --git a/lib/PublicInbox/Emergency.pm b/lib/PublicInbox/Emergency.pm
index 4ee86215..67f27bc7 100644
--- a/lib/PublicInbox/Emergency.pm
+++ b/lib/PublicInbox/Emergency.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2016 all contributors
+# Copyright (C) 2016-2021 all contributors
# License: AGPL-3.0+
#
# Emergency Maildir delivery for MDA
@@ -7,18 +7,20 @@ use strict;
use warnings;
use Fcntl qw(:DEFAULT SEEK_SET);
use Sys::Hostname qw(hostname);
-use IO::Handle;
+use IO::Handle; # ->flush, ->autoflush
sub new {
my ($class, $dir) = @_;
- -d $dir or mkdir($dir) or die "failed to mkdir($dir): $!\n";
foreach (qw(new tmp cur)) {
my $d = "$dir/$_";
next if -d $d;
- -d $d or mkdir($d) or die "failed to mkdir($d): $!\n";
+ require File::Path;
+ if (!File::Path::mkpath($d) && !-d $d) {
+ die "failed to mkpath($d): $!\n";
+ }
}
- bless { dir => $dir, files => {}, t => 0, cnt => 0 }, $class;
+ bless { dir => $dir, files => {}, t => 0, cnt => 0, pid => $$ }, $class;
}
sub _fn_in {
@@ -75,6 +77,7 @@ sub fh {
sub commit {
my ($self) = @_;
+ $$ == $self->{pid} or return; # no-op in forked child
delete $self->{fh};
my $tmp = delete $self->{tmp} or return;