Skip Menu |
 

This queue is for tickets about the PathTools CPAN distribution.

Report information
The Basics
Id: 39260
Status: open
Priority: 0/
Queue: PathTools

People
Owner: Nobody in particular
Requestors: jkeenan [...] cpan.org
SHLOMIF [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 3.28_01
Fixed in: (no value)



Subject: [PATCH] _perl_abs_path doesn't handle the case of a non-existent file in an existing dir
Download (untitled) / with headers
text/plain 443b
As can be seen here: http://www.nntp.perl.org/group/perl.cpan.testers/2008/09/msg2204098.html There's an incompatibility between the XS abs_path() and _perl_abs_path(): if one references a non-existent filename of an existing directory, then the XS abs_path will return a correct results and _perl_abs_path will warn and return nothing. This patch adds a testcase for the problem, and patches Cwd.pm to fix it. Regards, -- Shlomi Fish
Subject: non-exist-file.patch
--- ./t/cwd.t.orig 2008-09-14 10:34:33.618286763 +0300 +++ ./t/cwd.t 2008-09-14 10:50:34.037037599 +0300 @@ -18,11 +18,11 @@ use Test::More; require VMS::Filespec if $^O eq 'VMS'; -my $tests = 30; +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'; -$tests += 4 if $EXTRA_ABSPATH_TESTS; +$tests += 5 if $EXTRA_ABSPATH_TESTS; plan tests => $tests; SKIP: { @@ -197,7 +197,27 @@ path_ends_with(Cwd::_perl_abs_path($path), 'cwd.t', '_perl_abs_path() can be invoked on a file') if $EXTRA_ABSPATH_TESTS; +{ + mkdir("existing-dir", 0777); + my $path = File::Spec->catfile( + File::Spec->curdir(), 'existing-dir', "non-existent-file.txt" + ); + path_ends_with( + Cwd::abs_path($path), + 'non-existent-file.txt', + 'abs_path() can be invoked on a non-exist file in an existing dir' + ); + if ($EXTRA_ABSPATH_TESTS) + { + path_ends_with( + Cwd::_perl_abs_path($path), + 'non-existent-file.txt', + '_perl_abs_path() can be invoked on a non-exist file in an existing dir' + ); + } + rmdir("existing-dir"); +} SKIP: { my $file; --- ./Cwd.pm.orig 2008-09-14 10:49:27.443037749 +0300 +++ ./Cwd.pm 2008-09-14 11:08:21.863636314 +0300 @@ -502,19 +502,26 @@ sub _perl_abs_path { my $start = @_ ? shift : '.'; - my($dotdots, $cwd, @pst, @cst, $dir, @tst); + my($dotdots, $cwd, @pst, @cst, $dir, @tst, $file); unless (@cst = stat( $start )) { - _carp("stat($start): $!"); + my $err = $!; + # Check for a non-existent file inside an existing directory. + if (($dir, $file) = $start =~ m{^(.*)/(.+)$}) { + if (-d $dir) { + return abs_path($dir) . "/$file"; + } + } + _carp("stat($start): $err"); return ''; } unless (-d _) { # Make sure we can be invoked on plain files, not just directories. # NOTE that this routine assumes that '/' is the only directory separator. - - my ($dir, $file) = $start =~ m{^(.*)/(.+)$} + + ($dir, $file) = $start =~ m{^(.*)/(.+)$} or return cwd() . '/' . $start; # Can't use "-l _" here, because the previous stat was a stat(), not an lstat().
Is there any progress in getting this patch applied?
Download (untitled) / with headers
text/plain 403b
On Sun Oct 05 04:48:29 2008, SHLOMIF wrote: Show quoted text
> Is there any progress in getting this patch applied?
Apparently not. :-( Shlomi, given that Cwd is maintained by Perl 5 Porters in blead, if this is still an issue, you have the option of creating a new patch against dist/Cwd/Cwd.pm and dist/Cwd/t/cwd.t in blead and attaching that to an email to perlbug at perl dot org. Thank you very much. Jim Keenan
Download (untitled) / with headers
text/plain 577b
Hi Jim, On Sat Nov 23 20:16:57 2013, JKEENAN wrote: Show quoted text
> On Sun Oct 05 04:48:29 2008, SHLOMIF wrote:
> > Is there any progress in getting this patch applied?
> > Apparently not. :-( > > Shlomi, given that Cwd is maintained by Perl 5 Porters in blead, if > this is still an issue, you have the option of creating a new patch > against dist/Cwd/Cwd.pm and dist/Cwd/t/cwd.t in blead and attaching > that to an email to perlbug at perl dot org.
I've done that now - thanks! Also see: https://github.com/shlomif/perl/tree/Cwd-rt39260-bug-non-exist-file Regards, -- Shlomi Fish


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.