Combination of File::Spec->catdir() and do FILE problematic #15976
Comments
From @jkeenanCreated by jkeenan@zareason.(none)See https://rt.cpan.org/Ticket/Display.html?id=121633. The patch attached brings Time-HiRes's Makefile.PL into conformance with Perl Info
|
From @jkeenan0001-Show-how-File-Spec-catfile-handles-leading.patchFrom c0607ef1f1b523e71a423f1fc1a5debf4b6a6cf8 Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Fri, 12 May 2017 08:58:56 -0400
Subject: [PATCH] Show how File::Spec->catfile handles leading '.'.
This implies need to modify code where, in:
do $hints;
... $hints has been assigned a string composed by, e.g.,
$hints = File::Spec->catfile('.', 'hints', 'Makefile.PL');
---
dist/PathTools/t/Spec.t | 2 ++
dist/Time-HiRes/Makefile.PL | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/dist/PathTools/t/Spec.t b/dist/PathTools/t/Spec.t
index 0255bdb..8b9bcc7 100644
--- a/dist/PathTools/t/Spec.t
+++ b/dist/PathTools/t/Spec.t
@@ -61,6 +61,8 @@ my @tests = (
[ "Unix->catfile('a', do { my \$x = 'b'.chr(0xaf); use utf8 (); utf8::upgrade(\$x); \$x })", 'a/b'.chr(0xaf) ],
) : ()),
[ "Unix->catfile(substr('foo', 2))", 'o' ],
+# https://rt.cpan.org/Ticket/Display.html?id=121633
+[ "Unix->catfile('.', 'hints', 'Makefile.PL')", 'hints/Makefile.PL' ],
[ "Unix->splitpath('file')", ',,file' ],
[ "Unix->splitpath('/d1/d2/d3/')", ',/d1/d2/d3/,' ],
diff --git a/dist/Time-HiRes/Makefile.PL b/dist/Time-HiRes/Makefile.PL
index ca4d4dc..66691fd 100644
--- a/dist/Time-HiRes/Makefile.PL
+++ b/dist/Time-HiRes/Makefile.PL
@@ -417,11 +417,11 @@ sub DEFINE {
}
sub init {
- my $hints = File::Spec->catfile(".", "hints", "$^O.pl");
+ my $hints = File::Spec->catfile("hints", "$^O.pl");
if (-f $hints) {
print "Using hints $hints...\n";
local $self;
- do $hints;
+ do "./$hints";
if (exists $self->{LIBS}) {
$LIBS = $self->{LIBS};
print "Extra libraries: @$LIBS...\n";
--
2.7.4
|
From leejebay@hotmail.comConfigure and perl -V that showed this below. CFLAGS='-m64 -mtune=nocona' ./Configure -Dprefix=/opt/tools -Dotherlibdirs=/opt/tools/testing/lib -d -A ccflags=-fPIC Summary of my perl5 (revision 5 version 26 subversion 0) configuration: Characteristics of this binary (from libperl): |
The RT System itself - Status changed from 'new' to 'open' |
From @LeontOn Fri, May 12, 2017 at 4:34 PM, James E Keenan <perlbug-followup@perl.org>
I think this needs to be fixed before we put out an RC2 Leon |
From @jkeenanOn Sun, 14 May 2017 14:00:19 GMT, LeonT wrote:
If you were to ask me to look at the following line of code: ##### ... and then state the content of $hints -- without looking at the documentation and without consulting all the tests for this syntax in dist/PathTools/t/Spec.t -- I would probably "off the top of my head" responded: ##### If that were true, then the 'do $hints;' in dist/Time-HiRes/Makefile.PL would be perfectly fine. But in reality, that line of code produces: ##### ... in which case 'do $hints' would no longer be valid in the era of no-dot-by-default-in-@INC. File::Spec->catdir's behavior is plausible, but not necessarily what you would guess it to be. AFAICT, this is the only place in the core distribution where the arguments to File::Spec->catdir() start with '.' and where the result is used in 'do EXPR'. There may well be lots of code on CPAN or in the wild that combines File::Spec->catdir(".", @other_args) and do EXPR. Perhaps someone could do a grep of CPAN to identify such cases. But I think that if my patch is applied we will no longer have a blocker to 5.26.0. Thank you very much. -- |
From @jkeenanOn Sun, 14 May 2017 15:09:19 GMT, jkeenan wrote:
commit 8b69401 fix cases where 'do file' should be 'do ./file'. Inline Patchdiff --git a/dist/Time-HiRes/Makefile.PL b/dist/Time-HiRes/Makefile.PL
index ccad6a3..ca4d4dc 100644
--- a/dist/Time-HiRes/Makefile.PL
+++ b/dist/Time-HiRes/Makefile.PL
@@ -417,7 +417,7 @@ sub DEFINE {
}
sub init {
- my $hints = File::Spec->catfile("hints", "$^O.pl");
+ my $hints = File::Spec->catfile(".", "hints", "$^O.pl");
if (-f $hints) {
##### Dave, apply my more recent patch as needed.
-- |
From @jkeenanOn Sun, 14 May 2017 15:09:19 GMT, jkeenan wrote:
I grepped CPAN for files which contained 'catfile' and, within the next 10 lines of code, also matched '\bdo\b'. My program caught some false positives, but the only true positive I came up with was that in Time-HiRes's Makefile.PL -- the subject of this ticket. Hence, once we correct that file, we no longer have a blocker for 5.26.0. Thank you very much. -- |
From @xsawyerxOn 05/14/2017 03:59 PM, Leon Timmermans wrote:
I agree. |
From @iabynOn Tue, May 16, 2017 at 11:35:52PM +0200, Sawyer X wrote:
I've just pushed the Time::HiRes part of James's patch as -- |
From zefram@fysh.orgTime::HiRes was fixed long ago. Is there any other action to take on -zefram |
From @jkeenanOn Mon, 18 Dec 2017 03:33:08 GMT, zefram@fysh.org wrote:
In commit 9f6291f, I applied the PathTools part of my patch, which demonstrates how File::Spec->catfile works when '.' is the first argument. Marking ticket Resolved. Thank you very much. -- |
@jkeenan - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#131296 (status was 'resolved')
Searchable as RT131296$
The text was updated successfully, but these errors were encountered: