]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Emergency.pm
emergency: create full path to PI_EMERGENCY
[public-inbox.git] / lib / PublicInbox / Emergency.pm
index e402d30f848342800efb4891c46fc0b826dd585f..b705e776e676c874ffc7ad0f6c00753bbe1e6e03 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Emergency Maildir delivery for MDA
@@ -7,7 +7,7 @@ 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) = @_;
@@ -16,9 +16,11 @@ sub new {
                my $d = "$dir/$_";
                next if -d $d;
                require File::Path;
-               File::Path::mkpath($d); # croaks on fatal errors
+               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;