From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/3] treewide: use *nix-specific dirname regexps
Date: Wed, 11 Aug 2021 11:26:16 +0000 [thread overview]
Message-ID: <20210811112618.24084-2-e@80x24.org> (raw)
In-Reply-To: <20210811112618.24084-1-e@80x24.org>
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) = @_;
next prev parent reply other threads:[~2021-08-11 11:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-11 11:26 [PATCH 0/3] lei pathname canonicalization fixes Eric Wong
2021-08-11 11:26 ` Eric Wong [this message]
2021-08-11 11:26 ` [PATCH 2/3] lei_saved_search: canonicalized relative save paths Eric Wong
2021-08-11 11:26 ` [PATCH 3/3] lei: attempt to canonicalize away "/../" pathnames Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210811112618.24084-2-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).