From 4c6f9a39621fdae852e0655b7db3d61f03c716c5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 11 Aug 2021 11:26:16 +0000 Subject: treewide: use *nix-specific dirname regexps None of our code elsewhere accounts for non-*nix pathnames and it's not worth our time to start. So stop wasting CPU cycles giving the illusion that we'd care about non-*nix pathnames. --- lib/PublicInbox/IMAPTracker.pm | 4 ++-- lib/PublicInbox/LEI.pm | 2 +- lib/PublicInbox/OverIdx.pm | 4 ++-- lib/PublicInbox/Xapcmd.pm | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/IMAPTracker.pm b/lib/PublicInbox/IMAPTracker.pm index 5eb33cf7..2fd66440 100644 --- a/lib/PublicInbox/IMAPTracker.pm +++ b/lib/PublicInbox/IMAPTracker.pm @@ -75,9 +75,9 @@ sub new { } if (!-f $dbname) { require File::Path; - require File::Basename; require PublicInbox::Spawn; - File::Path::mkpath(File::Basename::dirname($dbname)); + my ($dir) = ($dbname =~ m!(.*?/)[^/]+\z!); + File::Path::mkpath($dir); open my $fh, '+>>', $dbname or die "failed to open $dbname: $!"; PublicInbox::Spawn::nodatacow_fd(fileno($fh)); } diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index e6f763e1..be4754df 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -798,7 +798,7 @@ sub _lei_cfg ($;$) { delete $self->{cfg}; return bless {}, 'PublicInbox::Config'; } - my (undef, $cfg_dir, undef) = File::Spec->splitpath($f); + my ($cfg_dir) = ($f =~ m!(.*?/)[^/]+\z!); -d $cfg_dir or mkpath($cfg_dir) or die "mkpath($cfg_dir): $!\n"; open my $fh, '>>', $f or die "open($f): $!\n"; @st = stat($fh) or die "fstat($f): $!\n"; diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm index 8f7cf2bb..e0893337 100644 --- a/lib/PublicInbox/OverIdx.pm +++ b/lib/PublicInbox/OverIdx.pm @@ -463,8 +463,8 @@ sub create { }; unless (-r $fn) { require File::Path; - require File::Basename; - File::Path::mkpath(File::Basename::dirname($fn)); + my ($dir) = ($fn =~ m!(.*?/)[^/]+\z!); + File::Path::mkpath($dir); } # create the DB: PublicInbox::Over::dbh($self); diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index 8b8958c7..588e7b94 100644 --- a/lib/PublicInbox/Xapcmd.pm +++ b/lib/PublicInbox/Xapcmd.pm @@ -8,7 +8,6 @@ use PublicInbox::Over; use PublicInbox::SearchIdx; use File::Temp 0.19 (); # ->newdir use File::Path qw(remove_tree); -use File::Basename qw(dirname); use POSIX qw(WNOHANG _exit); # support testing with dev versions of Xapian which installs @@ -199,7 +198,7 @@ sub prepare_run { warn "--reshard=$reshard ignored for v1 $ibx->{inboxdir}\n"; } - my $dir = dirname($old); + my ($dir) = ($old =~ m!(.*?/)[^/]+/*\z!); same_fs_or_die($dir, $old); my $v = PublicInbox::Search::SCHEMA_VERSION(); my $wip = File::Temp->newdir("xapian$v-XXXX", DIR => $dir); @@ -431,7 +430,7 @@ sub cpdb ($$) { # cb_spawn callback my ($tmp, $ft); local %SIG = %SIG; if ($opt->{compact}) { - my $dir = dirname($new); + my ($dir) = ($new =~ m!(.*?/)[^/]+/*\z!); same_fs_or_die($dir, $new); $ft = File::Temp->newdir("$new.compact-XXXX", DIR => $dir); setup_signals(); -- cgit v1.2.3-24-ge0c7