From: Eric Wong Date: Tue, 12 Nov 2024 20:34:30 +0000 (+0000) Subject: cindex: rework path canonicalization check X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31b603f84c680c70061ab6dc4107d8442e153abb;p=thirdparty%2Fpublic-inbox.git cindex: rework path canonicalization check While reading the code, I noticed inadvertant `$_' use when the loop iterator is `$d'. Using `$_' here would result in uninitialized variable access. I've yet to hit this case in real-world access. Furthermore, we can use a single pass to canonicalize existing directories instead of relying on a grep block, first. Finally, favor File::Spec::Functions since `->' method dispatch is slower than normal subroutine calls by a small amount even when both the package and method names are static and known early in advance.. --- diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm index ff3db8bad..13533a00d 100644 --- a/lib/PublicInbox/CodeSearchIdx.pm +++ b/lib/PublicInbox/CodeSearchIdx.pm @@ -56,7 +56,7 @@ use PublicInbox::PktOp; use PublicInbox::IPC qw(nproc_shards); use POSIX qw(WNOHANG SEEK_SET strftime); use File::Path (); -use File::Spec (); +use File::Spec::Functions qw(canonpath); use List::Util qw(max); use PublicInbox::SHA qw(sha256_hex sha_all); use PublicInbox::Search qw(xap_terms); @@ -1341,15 +1341,15 @@ sub cidx_run { # main entry point delete $REINDEX->{lock_path}; $REINDEX->dbh; } - my @nc = grep { File::Spec->canonpath($_) ne $_ } @{$self->{git_dirs}}; - if (@nc) { - warn "E: BUG? paths in $self->{cidx_dir} not canonicalized:\n"; - for my $d (@{$self->{git_dirs}}) { - my $c = File::Spec->canonpath($_); - warn "E: $d => $c\n"; - $d = $c; - } - warn "E: canonicalized and attempting to continue\n"; + my $cwarn; + for my $d (@{$self->{git_dirs}}) { + my $c = canonpath $d; + next if $c eq $d; + $cwarn = warn <{cidx_dir} not canonicalized: +EOM + warn "E: $d => $c\n"; + $d = $c; } if (defined(my $excl = $self->{-opt}->{exclude})) { my $re = '(?:'.join('\\z|', map {