diff options
author | Eric Wong <e@80x24.org> | 2023-02-22 17:25:55 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-02-22 21:36:19 +0000 |
commit | f2bb17a54f42a276b993b7dd49c06239141eafe4 (patch) | |
tree | e3a69912bea60446d36be27cd295dbaa9fb20639 /lib/PublicInbox/Emergency.pm | |
parent | cd73e06277ae9286e9a823b591ca5187ce35cdca (diff) | |
download | public-inbox-f2bb17a54f42a276b993b7dd49c06239141eafe4.tar.gz |
File::Path already accounts for the existence of directories, handles races from redundant mkdir(2), and croaks on unrecoverable errors. So there's no point in doing any of that on our end. Furthermore, avoiding the overhead of loading File::Path doesn't seem worth it to save 20-60ms given the overhead of loading our other code. Instead, try to reduce optree overhead on our code, instead, since File::Path gets used in a bunch of places. We'll also favor the newer make_path for multi-directory invocations to avoid bloating our own optree to create an arrayref, but mkpath is one fewer subroutine call within File::Path itself, right now.
Diffstat (limited to 'lib/PublicInbox/Emergency.pm')
-rw-r--r-- | lib/PublicInbox/Emergency.pm | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/lib/PublicInbox/Emergency.pm b/lib/PublicInbox/Emergency.pm index 5a1ed1d7..56c58dd1 100644 --- a/lib/PublicInbox/Emergency.pm +++ b/lib/PublicInbox/Emergency.pm @@ -9,18 +9,11 @@ use Fcntl qw(:DEFAULT SEEK_SET); use Sys::Hostname qw(hostname); use IO::Handle; # ->flush use Errno qw(EEXIST); +use File::Path (); sub new { my ($class, $dir) = @_; - - foreach (qw(new tmp cur)) { - my $d = "$dir/$_"; - next if -d $d; - require File::Path; - if (!File::Path::mkpath($d) && !-d $d) { - die "failed to mkpath($d): $!\n"; - } - } + File::Path::make_path(map { $dir.$_ } qw(/tmp /new /cur)); bless { dir => $dir, t => 0 }, $class; } |