]> Sergey Matveev's repositories - public-inbox.git/commitdiff
treewide: use *nix-specific dirname regexps
authorEric Wong <e@80x24.org>
Wed, 11 Aug 2021 11:26:16 +0000 (11:26 +0000)
committerEric Wong <e@80x24.org>
Wed, 11 Aug 2021 21:50:07 +0000 (21:50 +0000)
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
lib/PublicInbox/LEI.pm
lib/PublicInbox/OverIdx.pm
lib/PublicInbox/Xapcmd.pm
script/public-inbox-init
t/init.t

index 5eb33cf752f438ee1f352f1442c58bf9ab00baba..2fd66440df04ee540f5ce2f96e6e749d44a2e49e 100644 (file)
@@ -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));
        }
index e6f763e1067869e0a7c6d3bb8a90e2b544f45e0d..be4754df8d162448fe9a81b69093d3242084f6d2 100644 (file)
@@ -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";
index 8f7cf2bb97228b49f4b653ee94ecfa90d74dc3f4..e0893337e7843461740ad607ecff7aa5e7dd9b6f 100644 (file)
@@ -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);
index 8b8958c71ffbc6749427215664469eab2ae1378e..588e7b9408617e1fb92adef2a7b91dde3014820d 100644 (file)
@@ -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();
index 6fac4d184d14a822e2f9324cb841fbe26ecc4612..ced882359870bcf183df91833e4bf126fb4a6974 100755 (executable)
@@ -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
 
index 7382e05bc99e2987656f5bd5c831f3e938f938ab..efa3314d365b03c049a9c2939b2529992d2a6874 100644 (file)
--- 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) = @_;