Open p5pRT opened 12 years ago
[ Applies to 5.10.1\, 5.12.2\, 5.14.2\, blead\, etc ]
Whenever I build Perl on my web host\, I get a failure in Cwd.
# Failed test at t/cwd.t line 209. # '/home/ikegami/usr/perlbrew/build/perl-5.14.2/dist/Cwd/t/linktest' # doesn't match '(?^i:\/home\/ikegami\/usr\/perlbrew\/build\/perl\-5\.14\.2\/dist\/Cwd\/t\/_ptrslt_\/_path_\/_to_\/_a_\/_dir_$)' # Looks like you failed 1 test of 34. ../dist/Cwd/t/cwd.t ............................................... Dubious\, test returned 1 (wstat 256\, 0x100) Failed 1/34 subtests (less 1 skipped subtest: 32 okay)
C\<abs_path> is a function that returns an absolute path with symbolic links resolved. The failing check tests a pure perl version of abs_path called C\<_perl_abs_path>. The pure perl version does not resolve symlinks if any ancestor of the symlink's target directory cannot be read\, and /home cannot be read on my web host.
You can test this yourself using the attached script (extracted from cwd.t) and C\<\< chmod u-r .. >>.
I don't know if C\<_perl_abs_path> should croak or if the test shouldn't fail\, but they currently disagree as to what is acceptable\, forcing me to force install Perl every time. This is especially silly since C\<_perl_abs_path> is only used when "the XS version doesn't load" (according to a comment).
- Eric
On Fri\, Feb 3\, 2012 at 10:03 PM\, Eric Brine \perlbug\-followup@​perl\.orgwrote:
You can test this yourself using the attached script (extracted from cwd.t) and C\<\< chmod u-r .. >>.
Oops\, now attached.
On Fri Feb 03 19:03:14 2012\, ikegami@adaelis.com wrote:
This is a bug report for perl from ikegami@adaelis.com\, generated with the help of perlbug 1.39 running under perl 5.10.1.
----------------------------------------------------------------- [Please describe your issue here]
[ Applies to 5.10.1\, 5.12.2\, 5.14.2\, blead\, etc ]
Whenever I build Perl on my web host\, I get a failure in Cwd.
# Failed test at t/cwd.t line 209. # '/home/ikegami/usr/perlbrew/build/perl-5.14.2/dist/Cwd/t/linktest' # doesn't match '(?^i:\/home\/ikegami\/usr\/perlbrew\/build\/perl\- 5\.14\.2\/dist\/Cwd\/t\/_ptrslt_\/_path_\/_to_\/_a_\/_dir_$)' # Looks like you failed 1 test of 34. ../dist/Cwd/t/cwd.t ............................................... Dubious\, test returned 1 (wstat 256\, 0x100) Failed 1/34 subtests (less 1 skipped subtest: 32 okay)
C\<abs_path> is a function that returns an absolute path with symbolic links resolved. The failing check tests a pure perl version of abs_path called C\<_perl_abs_path>. The pure perl version does not resolve symlinks if any ancestor of the symlink's target directory cannot be read\, and /home cannot be read on my web host.
You can test this yourself using the attached script (extracted from cwd.t) and C\<\< chmod u-r .. >>.
I don't know if C\<_perl_abs_path> should croak or if the test shouldn't fail\, but they currently disagree as to what is acceptable\, forcing me to force install Perl every time. This is especially silly since C\<_perl_abs_path> is only used when "the XS version doesn't load" (according to a comment).
- Eric
I get your point\, but when I tried to replicate the problem on my machine in a slightly modified manner\, I got a result that suggested a problem in Cwd::abs_path() *even before* looking at Cwd::_perl_abs_path().
I split your test file into two separate programs so that I could create the test directories\, then modify the directory permissions as you suggested\, then create the symlink and run the second program\, which was essentially the remainder of yours. Both files are attached.
In 'a_109760_cwdtest.pl'\, I remove the test directories and symlink if they're still present from a previous run\, then create the test directories.
In the first pass\, I leave directory permissions untouched and run 'b_109760_cwdtest.pl'\, which creates the symlinks\, performs tests (which all pass)\, and then cleans up after itself.
The output is therefore: ######### $ prove -v a_109760_cwdtest.pl a_109760_cwdtest.pl .. ok 1 - mkpath created expected number of directories 1..1 ok All tests successful. Files=1\, Tests=1\, 1 wallclock secs ( 0.12 usr 0.03 sys + 0.14 cusr 0.04 csys = 0.33 CPU) Result: PASS
$ prove -v b_109760_cwdtest.pl b_109760_cwdtest.pl .. ok 1 - symlink to test_dir created # abs_path: /Users/jimk/learn/perl/p5p/_ptrslt_/_path_/_to_/_a_/_dir_ ok 2 - Cwd::abs_path matches File::Spec->rel2abs ok 3 - Cwd::fast_abs_path matches File::Spec->rel2abs ok 4 - Cwd::_perl_abs_path matches File::Spec->rel2abs 1..4 ok All tests successful. Files=1\, Tests=4\, 0 wallclock secs ( 0.12 usr 0.04 sys + 0.15 cusr 0.07 csys = 0.38 CPU) Result: PASS ##########
In the second pass\, I run the first program\, then chmod u-r ..\, then run the second program. This time\, the output is:
########## $ prove -v a_109760_cwdtest.pl a_109760_cwdtest.pl .. ok 1 - mkpath created expected number of directories 1..1 ok All tests successful. Files=1\, Tests=1\, 0 wallclock secs ( 0.12 usr 0.04 sys + 0.13 cusr 0.04 csys = 0.33 CPU) Result: PASS
$ chmod u-r ..
$ prove -v b_109760_cwdtest.pl b_109760_cwdtest.pl .. ok 1 - symlink to test_dir created # abs_path: Use of uninitialized value $abs_path in concatenation (.) or string at b_109760_cwdtest.pl line 21. Cannot chdir back to : No such file or directory at b_109760_cwdtest.pl line 22.
1..1 # Looks like your test exited with 255 just after 1. Dubious\, test returned 255 (wstat 65280\, 0xff00) All 1 subtests passed
Test Summary Report
b_109760_cwdtest.pl (Wstat: 65280 Tests: 1 Failed: 0) Non-zero exit status: 255 Files=1\, Tests=1\, 0 wallclock secs ( 0.12 usr 0.04 sys + 0.14 cusr 0.04 csys = 0.34 CPU) Result: FAIL ############
I read this as saying that\, once the higher directory had been rendered unreadable\, the call to Cwd::abs_path() at line 20 essentially failed; it returned an undefined value.
######### 20 my $abs_path = Cwd::abs_path($file); 21 note("abs_path: $abs_path"); #########
So I doubt the problem is *only* in Cwd::_perl_abs_path().
Thank you very much. Jim Keenan
The RT System itself - Status changed from 'new' to 'open'
This is a bug report for perl from gottreu@gmail.com\, generated with the help of perlbug 1.39 running under perl 5.19.1.
From 5f28c1a5e9dd996eeec4fc4aade74a400a3af87e Mon Sep 17 00:00:00 2001 From: Brian Gottreu \gottreu@​gmail\.com Date: Thu\, 13 Jun 2013 14:33:36 -0500 Subject: [PATCH] Skip _perl_abs_path() tests when they will fail with no ill effects MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.7.10.4"
This is a multi-part message in MIME format. --------------1.7.10.4 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit
AUTHORS | 1 + dist/Cwd/t/cwd.t | 11 +++++++++++ 2 files changed\, 12 insertions(+)
--------------1.7.10.4 Content-Type: text/x-patch; name="0001-Skip-_perl_abs_path-tests-when-they-will-fail-with-n.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-Skip-_perl_abs_path-tests-when-they-will-fail-with-n.patch"
Flags: category=core severity=low
Site configuration information for perl 5.19.1:
Configured by gottreu at Thu Jun 13 11:58:47 CDT 2013.
Summary of my perl5 (revision 5 version 19 subversion 1) configuration: Commit id: 6b28e74b02b8a23cdbd7fd19c2874a19c37827de Platform: osname=linux\, osvers=3.2.0-4-amd64\, archname=x86_64-linux uname='linux frylock 3.2.0-4-amd64 #1 smp debian 3.2.39-2 x86_64 gnulinux ' config_args='-des -Dprefix=/home/gottreu/devperl -Dusedevel' hint=recommended\, useposix=true\, d_sigaction=define useithreads=undef\, usemultiplicity=undef useperlio=define\, d_sfio=undef\, uselargefiles=define\, usesocks=undef use64bitint=define\, use64bitall=define\, uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler: cc='cc'\, ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'\, optimize='-O2'\, cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion=''\, gccversion='4.7.2'\, gccosandvers='' intsize=4\, longsize=8\, ptrsize=8\, doublesize=8\, byteorder=12345678 d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=16 ivtype='long'\, ivsize=8\, nvtype='double'\, nvsize=8\, Off_t='off_t'\, lseeksize=8 alignbytes=8\, prototype=define Linker and Libraries: ld='cc'\, ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=\, so=so\, useshrplib=false\, libperl=libperl.a gnulibc_version='2.13' Dynamic Linking: dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags='-Wl\,-E' cccdlflags='-fPIC'\, lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'
Locally applied patches:
@INC for perl 5.19.1: /home/gottreu/devperl/lib/site_perl/5.19.1/x86_64-linux /home/gottreu/devperl/lib/site_perl/5.19.1 /home/gottreu/devperl/lib/5.19.1/x86_64-linux /home/gottreu/devperl/lib/5.19.1 .
Environment for perl 5.19.1: HOME=/home/gottreu LANG=en_US.UTF-8 LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/gottreu/bin:/home/gottreu/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games PERL_BADLANG (unset) SHELL=/bin/bash
On Thu Jun 13 13:10:46 2013\, gottreu wrote:
This is a bug report for perl from gottreu@gmail.com\, generated with the help of perlbug 1.39 running under perl 5.19.1.
From 5f28c1a5e9dd996eeec4fc4aade74a400a3af87e Mon Sep 17 00:00:00 2001 From: Brian Gottreu \gottreu@​gmail\.com Date: Thu\, 13 Jun 2013 14:33:36 -0500 Subject: [PATCH] Skip _perl_abs_path() tests when they will fail with no ill effects MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.7.10.4"
This is a multi-part message in MIME format. --------------1.7.10.4 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit
--- AUTHORS | 1 + dist/Cwd/t/cwd.t | 11 +++++++++++ 2 files changed\, 12 insertions(+)
--------------1.7.10.4 Content-Type: text/x-patch; name="0001-Skip-_perl_abs_path-tests-when- they-will-fail-with-n.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-Skip-_perl_abs_path- tests-when-they-will-fail-with-n.patch"
diff --git a/AUTHORS b/AUTHORS index 44f52e2..b00e7e5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -163\,6 +163\,7 @@ Brian Carlson \brian\.carlson@​cpanel\.net Brian Clarke \clarke@​appliedmeta\.com brian d foy \brian\.d\.foy@​gmail\.com Brian Fraser \fraserbn@​gmail\.com +Brian Gottreu \gottreu@​gmail\.com Brian Greenfield \briang@​cpan\.org Brian Grossman Brian Harrison \brie@​corp\.home\.net diff --git a/dist/Cwd/t/cwd.t b/dist/Cwd/t/cwd.t index f7b03ed..3c83855 100644 --- a/dist/Cwd/t/cwd.t +++ b/dist/Cwd/t/cwd.t @@ -40\,6 +40\,17 @@ my $tests = 31; # _perl_abs_path() currently only works when the directory separator # is '/'\, so don't test it when it won't work. my $EXTRA_ABSPATH_TESTS = ($Config{prefix} =~ m/\//) && $^O ne 'cygwin'; +# _perl_abs_path() uses readdir() on all the directories in the path +# passed to it. If perl is built under /home (for example) and /home is +# set to executable but not readable\, then the extra abspath tests will +# fail even though the perl built is perfectly fine. +if($EXTRA_ABSPATH_TESTS) { + my @dirs = File::Spec->splitdir(cwd()); + for(0..$#dirs) { + my $parent_dir = File::Spec->catdir(@dirs[0..$_]); + $EXTRA_ABSPATH_TESTS = 0 unless -r $parent_dir; + } +} $tests += 4 if $EXTRA_ABSPATH_TESTS; plan tests => $tests;
Thanks for the patch. Can you elaborate a bit as to how it addresses the issues raised in the earlier posts in this RT?
Thank you very much. Jim Keenan
On Thu\, Jun 13\, 2013 at 10:21 PM\, James E Keenan via RT \< perlbug-followup@perl.org> wrote:
Thanks for the patch. Can you elaborate a bit as to how it addresses the issues raised in the earlier posts in this RT?
Looking into your earlier comments\, and testing to see if the patch addresses my problem.
Thanks for the patch. Can you elaborate a bit as to how it addresses the issues raised in the earlier posts in this RT?
It sort of didn't. It didn't solve the actual problem of _perl_abs_path() not resolving all the paths that abs_path() can. It just made some harmlessly failing tests not fail.
This new patch is an actual fix. I just translated the bsd_realpath() C function to Perl.
This is a bug report for perl from gottreu@gmail.com\, generated with the help of perlbug 1.39 running under perl 5.19.1.
From a380df6c6c1f9e17832236d07838efac3007a838 Mon Sep 17 00:00:00 2001 From: Brian Gottreu \gottreu@​gmail\.com Date: Thu\, 13 Jun 2013 22:26:22 -0500 Subject: [PATCH] Replace _perl_abs_path() with a version that does not require readable directories\, only executable ones. It's just a Perl version of the bsd_realpath() function already used by abs_path() for Unix systems. This version mimics the behavior of abs_path() more closely than the previous version. It returns undef on failure instead of the empty string. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.7.10.4"
This is a multi-part message in MIME format. --------------1.7.10.4 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit
AUTHORS | 1 + dist/Cwd/Cwd.pm | 129 ++++++++++++++++++++++++------------------------------- 2 files changed\, 56 insertions(+)\, 74 deletions(-)
--------------1.7.10.4 Content-Type: text/x-patch; name="0001-Replace-_perl_abs_path-with-a-version-that-does-not-.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-Replace-_perl_abs_path-with-a-version-that-does-not-.patch"
Flags: category=core severity=low
Site configuration information for perl 5.19.1:
Configured by gottreu at Thu Jun 13 17:46:12 CDT 2013.
Summary of my perl5 (revision 5 version 19 subversion 1) configuration: Derived from: 9152021db0fe677bcc7f8460e5d5419a79462abc Platform: osname=linux\, osvers=3.2.0-4-amd64\, archname=x86_64-linux uname='linux frylock 3.2.0-4-amd64 #1 smp debian 3.2.39-2 x86_64 gnulinux ' config_args='-des -Dprefix=/home/gottreu/devperl2 -Dusedevel' hint=recommended\, useposix=true\, d_sigaction=define useithreads=undef\, usemultiplicity=undef useperlio=define\, d_sfio=undef\, uselargefiles=define\, usesocks=undef use64bitint=define\, use64bitall=define\, uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler: cc='cc'\, ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'\, optimize='-O2'\, cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion=''\, gccversion='4.7.2'\, gccosandvers='' intsize=4\, longsize=8\, ptrsize=8\, doublesize=8\, byteorder=12345678 d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=16 ivtype='long'\, ivsize=8\, nvtype='double'\, nvsize=8\, Off_t='off_t'\, lseeksize=8 alignbytes=8\, prototype=define Linker and Libraries: ld='cc'\, ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=\, so=so\, useshrplib=false\, libperl=libperl.a gnulibc_version='2.13' Dynamic Linking: dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags='-Wl\,-E' cccdlflags='-fPIC'\, lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'
Locally applied patches:
@INC for perl 5.19.1: /home/gottreu/perl5/lib/perl5/x86_64-linux-gnu-thread-multi /home/gottreu/perl5/lib/perl5 /home/gottreu/devperl2/lib/site_perl/5.19.1/x86_64-linux /home/gottreu/devperl2/lib/site_perl/5.19.1 /home/gottreu/devperl2/lib/5.19.1/x86_64-linux /home/gottreu/devperl2/lib/5.19.1 .
Environment for perl 5.19.1: HOME=/home/gottreu LANG=en_US.UTF-8 LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/gottreu/bin:/home/gottreu/perl5/bin:/home/gottreu/perl5/perlbrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games PERL5LIB=/home/gottreu/perl5/lib/perl5/x86_64-linux-gnu-thread-multi:/home/gottreu/perl5/lib/perl5 PERLBREW_BASHRC_VERSION=0.42 PERLBREW_HOME=/home/gottreu/.perlbrew PERLBREW_PATH=/home/gottreu/perl5/perlbrew/bin PERLBREW_ROOT=/home/gottreu/perl5/perlbrew PERL_BADLANG (unset) PERL_LOCAL_LIB_ROOT=/home/gottreu/perl5 PERL_MB_OPT=--install_base /home/gottreu/perl5 PERL_MM_OPT=INSTALL_BASE=/home/gottreu/perl5 SHELL=/bin/bash
On Sat\, Feb 23\, 2013 at 8:35 PM\, James E Keenan via RT \< perlbug-followup@perl.org> wrote:
$ prove -v b_109760_cwdtest.pl
b_109760_cwdtest.pl .. ok 1 - symlink to test_dir created # abs_path: Use of uninitialized value $abs_path in concatenation (.) or string at b_109760_cwdtest.pl line 21. Cannot chdir back to : No such file or directory at b_109760_cwdtest.pl line 22.
I don't get that. I get something similar if I run "b" twice without running "a" in between
ok 1 - symlink to test_dir created Use of uninitialized value $abs_path in concatenation (.) or string at b.plline 21. # abs_path: linktest: No such file or directory at b.pl line 22. 1..1 # Looks like your test exited with 255 just after 1.
But if I execute the commands you executed in the order you said you did\, I get:
ok 1 - symlink to test_dir created # abs_path: /home/ikegami/projects/perl/_ptrslt_/_path_/_to_/_a_/_dir_ ok 2 - Cwd::abs_path matches File::Spec->rel2abs ok 3 - Cwd::fast_abs_path matches File::Spec->rel2abs not ok 4 - Cwd::_perl_abs_path matches File::Spec->rel2abs # Failed test 'Cwd::_perl_abs_path matches File::Spec->rel2abs' # at b.pl line 31. # '/home/ikegami/projects/perl/linktest' # doesn't match '(?^i:\/home\/ikegami\/projects\/perl\/_ptrslt_\/_path_\/_to_\/_a_\/_dir_$)' 1..4 # Looks like you failed 1 test of 4.
Brian's first patch ("Skip _perl_abs_path() tests when they will fail with no ill effects") does address the problem I reported\, and in an acceptable manner.
I don't have time to look at his alternate/second patch right now.
- Eric
Attached is a test (dist/Cwd/t/abs_path.t) that makes sure _perl_abs_path() and abs_path() return the same results.
#!./perl -w
use strict;
# XXX All the crossplatform stuff is cargo-cultedly copied from cwd.t use Cwd;
chdir 't';
use Config; use File::Spec; use File::Path qw(make_path remove_tree);
use lib File::Spec->catdir('t'\, 'lib'); use Test::More;
# _perl_abs_path() currently only works when the directory separator # is '/'\, so don't test it when it won't work. unless(($Config{prefix} =~ m/\//) && $^O ne 'cygwin') { plan skip_all => "only check _perl_abs_path() when the directory separator is '/'"; }
my @real_dirs = qw( _base_ _base_/ok _base_/ok/dir _base_/unreadable _base_/unreadable/dir _base_/unexec _base_/unexec/dir _base_/nothing _base_/nothing/dir );
my @real_files = qw( _base_/ok/file1 _base_/ok/dir/file2 _base_/unreadable/file3 _base_/unreadable/dir/file4 _base_/unexec/file5 _base_/unexec/dir/file6 _base_/nothing/file7 _base_/nothing/dir/file8 );
my %valid_links = qw( _base_/link-ok0 ok _base_/link-ok1 ok/file1 _base_/link-ok2 ok/dir _base_/link-ok3 ok/dir/file2 _base_/link-unreadable0 unreadable _base_/link-unreadable1 unreadable/file3 _base_/link-unreadable2 unreadable/dir _base_/link-unreadable3 unreadable/dir/file4
_base_/link-bin /bin _base_/link-rm /bin/rm );
my %broken_links = qw( _base_/link-unexec0 unexec _base_/link-unexec1 unexec/file5 _base_/link-unexec2 unexec/dir _base_/link-unexec3 unexec/dir/file6
_base_/link-nothing0 nothing _base_/link-nothing1 nothing/file7 _base_/link-nothing2 nothing/dir _base_/link-nothing3 nothing/dir/file8
_base_/link-loop link-loop
_base_/link-non-existant non-existant _base_/link-non-existant2 non/existant/dirs );
my @reg_paths = qw( _base_/../_base_/ok/file1 _base_/ok/dir/../file1 _base_/ok//file1 _base_/./ok/./file1 _base_/unreadable/dir/../../ok/file1 _base_/unreadable/../ok/file1 _base_/unexec/dir/../../ok/file1 _base_/unexec/../ok/file1 _base_/non-existant );
my @link_paths = qw( _base_/link-ok2/file2 _base_/link-ok2/../file1
_base_/link-ok2/file1 _base_/link-ok2/../file2 );
#my $tests = 1 + list_files("don't run cwd()"); my $tests = 1 + 3*list_reg_files() + 3*list_symlinks(); plan tests => $tests; my $cwd; my $CWD_WORKS = 0;
my $IsVMS = $^O eq 'VMS'; my $vms_unix_rpt = 0; if ($IsVMS) { require VMS::Filespec; use Carp; use Carp::Heavy; if (eval 'require VMS::Feature') { $vms_unix_rpt = VMS::Feature::current("filename_unix_report"); } else { my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || ''; $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i; } }
SKIP: { # Must find an external pwd (or equivalent) command. my $pwd = $^O eq 'MSWin32' ? "cmd" : "pwd"; my $pwd_cmd = ($^O eq "NetWare") ? "cd" : (grep { -x && -f } map { "$_/$pwd$Config{exe_ext}" } split m/$Config{path_sep}/\, $ENV{PATH})[0]; $pwd_cmd = 'SHOW DEFAULT' if $IsVMS; if ($^O eq 'MSWin32') { $pwd_cmd =~ s{/}{\\}g; $pwd_cmd = "$pwd_cmd /c cd"; } $pwd_cmd =~ s{\\}{/}g if ($^O eq 'dos');
skip "No native pwd command found to test against"\, 1 unless $pwd_cmd;
local @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)}; my ($pwd_cmd_untainted) = $pwd_cmd =~ /^(.+)$/; # Untaint. chomp(my $start = `$pwd_cmd_untainted`);
# Win32's cd returns native C:\ style $start =~ s{\\}{/}g if ($^O eq 'MSWin32' || $^O eq "NetWare"); if ($IsVMS) { # DCL SHOW DEFAULT has leading spaces $start =~ s/^\s+//;
# When in UNIX report mode\, need to convert to compare it. if ($vms_unix_rpt) { $start = VMS::Filespec::unixpath($start); # Remove trailing slash. $start =~ s{/$}{}; } } skip("'$pwd_cmd' failed\, nothing to test against"\, 1) if $?; skip("/afs seen\, paths unlikely to match"\, 1) if $start =~ m{/afs/};
# Darwin's getcwd(3) (which Cwd.xs:bsd_realpath() uses which # Cwd.pm:getcwd uses) has some magic related to the PWD # environment variable: if PWD is set to a directory that # looks about right (guess: has the same (dev\,ino) as the '.'?)\, # the PWD is returned. However\, if that path contains # symlinks\, the path will not be equal to the one returned by # /bin/pwd (which probably uses the usual walking upwards in # the path -trick). This situation is easy to reproduce since # /tmp is a symlink to /private/tmp. Therefore we invalidate # the PWD to force getcwd(3) to (re)compute the cwd in full. # Admittedly fixing this in the Cwd module would be better # long-term solution but deleting $ENV{PWD} should not be # done light-heartedly. --jhi delete $ENV{PWD} if $^O eq 'darwin';
$cwd = cwd; is($cwd\, $start\, 'cwd()') and $CWD_WORKS=1; }
eval { create_files(); SKIP: { compare_perl_and_xs( list_reg_files() ); compare_perl_and_xs( map { "$_/" } list_reg_files() ); if($CWD_WORKS) { compare_perl_and_xs( map { "$cwd/$_" } list_reg_files() ); } else { skip "cwd() may not be correct"\, scalar(list_reg_files()); } }
SKIP: { skip "no symlinks on this platform"\, (list_symlinks() * 3) unless $Config{d_symlink}; compare_perl_and_xs( list_symlinks() ); compare_perl_and_xs( map { "$_/" } list_symlinks() ); if($CWD_WORKS) { compare_perl_and_xs( map { "$cwd/$_" } list_symlinks() ); } else { skip "cwd() may not be correct"\, scalar(list_symlinks()); } } }; delete_files();
sub list_reg_files { my @all = (@real_dirs\, @real_files\, @reg_paths); return @all; }
sub list_symlinks { my @all = (sort(keys %valid_links)\, sort(keys %broken_links)\, @link_paths); return @all; }
sub compare_perl_and_xs { my @files = @_; for my $file (@files) { my $c = Cwd::abs_path($file); my $p = Cwd::_perl_abs_path($file); is($p\, $c) or diag("path: $file"); } }
sub create_files { make_path($_) for @real_dirs; system("touch $_") for @real_files; symlink($valid_links{$_}\, $_) for keys %valid_links; symlink($broken_links{$_}\, $_) for keys %broken_links; chmod 0311\, '_base_/unreadable'; chmod 0644\, '_base_/unexec'; chmod 0200\, '_base_/nothing'; }
sub delete_files { remove_tree("_base_"); }
Migrated from rt.perl.org#109760 (status was 'open')
Searchable as RT109760$