From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 15E3B1F8C7 for ; Wed, 11 Aug 2021 11:26:19 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/3] treewide: use *nix-specific dirname regexps Date: Wed, 11 Aug 2021 11:26:16 +0000 Message-Id: <20210811112618.24084-2-e@80x24.org> In-Reply-To: <20210811112618.24084-1-e@80x24.org> References: <20210811112618.24084-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 ++--- script/public-inbox-init | 3 +-- t/init.t | 1 - 6 files changed, 8 insertions(+), 11 deletions(-) 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(); diff --git a/script/public-inbox-init b/script/public-inbox-init index 6fac4d18..ced88235 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -93,8 +93,7 @@ $ng =~ m![^A-Za-z0-9/_\.\-\~\@\+\=:]! and require PublicInbox::Config; my $pi_config = PublicInbox::Config->default_file; -require File::Basename; -my $dir = File::Basename::dirname($pi_config); +my ($dir) = ($pi_config =~ m!(.*?/)[^/]+\z!); require File::Path; File::Path::mkpath($dir); # will croak on fatal errors diff --git a/t/init.t b/t/init.t index 7382e05b..efa3314d 100644 --- a/t/init.t +++ b/t/init.t @@ -6,7 +6,6 @@ use Test::More; use PublicInbox::Config; use PublicInbox::TestCommon; use PublicInbox::Admin; -use File::Basename; my ($tmpdir, $for_destroy) = tmpdir(); sub quiet_fail { my ($cmd, $msg) = @_;