Skip Menu |

This queue is for tickets about the PathTools CPAN distribution.

Report information
The Basics
Id: 73679
Status: new
Priority: 0/
Queue: PathTools

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

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



Subject: Cwd::abs_path fails if path contains \n on Cygwin

Bumped into this issue in the testcases for File::chdir  ( not really useful reading https://rt.cpan.org/Ticket/Display.html?id=72924 ) and discovered that Cwd::abs_path will consistently fail with "'Cannot chdir back to /home/Kent/$X: No such file or directory at " .. messages.

The most worrying part of this is $X is trimmed at the \n in the path, and characters after the \n are lost somehow.

It seems "abs_path" on cygwin maps to "fast_abs_path", which seems to be where the culprit is hiding. Using _perl_abs_path appears not to have the same defect, for whatever reason.

So, attached is a test file that replicates both my example problem scenario and a variety of other things that seem to work somewhat, for whatever reason, the only one of which appears not to work is Cwd::abs_path

Test failure is demonstrated on a rather recent blead 5.15.6 , but the problem also has been tested to happen on 5.14.1

Test output:

 

$ perl ./test.t
ok 1 - Can concat dirs with \n
ok 2 - mkdir is nonfatal with \n
ok 3 - chdir is nonfatal with \n
not ok 4 - abs_path doesn't fatal on \n
Show quoted text

#   Failed test 'abs_path doesn't fatal on \n'
#   at ./test.t line 32.
#          got: 'Cannot chdir back to /home/Kent/test5344: No such file or directory at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/5.15.6/cygwin-thread-multi-64int/Cwd.pm line 354
#       Cwd::_croak('Cannot chdir back to /home/Kent/test5344: No such file or dir...') called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/5.15.6/cygwin-thread-multi-64int/Cwd.pm line 658
#       Cwd::fast_abs_path() called at ./test.t line 31
#       main::__ANON__() called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6/Test/Fatal.pm line 23
#       Test::Fatal::__ANON__() called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6/Try/Tiny.pm line 71
#       eval {...} called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6/Try/Tiny.pm line 67
#       Try::Tiny::try('CODE(0x10443c88)', 'Try::Tiny::Catch=REF(0x104b20a8)') called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6/Test/Fatal.pm line 30
#       Test::Fatal::exception('CODE(0x104f4a28)') called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/5.15.6/cygwin-thread-multi-64int/Cwd.pm line 354
#       Cwd::_croak('Cannot chdir back to /home/Kent/test5344: No such file or dir...') called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/5.15.6/cygwin-thread-multi-64int/Cwd.pm line 658
#       Cwd::fast_abs_path() called at ./test.t line 31
#       main::__ANON__() called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6/Test/Fatal.pm line 23
#       Test::Fatal::__ANON__() called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6/Try/Tiny.pm line 71
#       eval {...} called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6/Try/Tiny.pm line 67
#       Try::Tiny::try('CODE(0x10443c88)', 'Try::Tiny::Catch=REF(0x104b20a8)') called at /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6/Test/Fatal.pm line 30
#       Test::Fatal::exception('CODE(0x104f4a28)') called at ./test.t line 32
# '
#     expected: undef
# Cwd::_perl_abs_path = /home/Kent/test5344
# newline
ok 5 - _perl_abs_path doesn't fatal on \n
Show quoted text
# updir is: ..
ok 6 - updir doesn't fatal on \n
Show quoted text
# curdir is: .
ok 7 - curdir doesn't fatal on \n
Show quoted text
# updir is: /home/Kent/test5344
# newline/..
ok 8 - rel2abs updir doesn't fatal on \n
Show quoted text
# curdir is: /home/Kent/test5344
# newline
ok 9 - rel2abs curdir doesn't fatal on \n
1..9
Show quoted text
# Looks like you failed 1 test of 9.
 

$ perl -V
Summary of my perl5 (revision 5 version 15 subversion 6) configuration:
  Snapshot of: 8756617677dbda9a9ac19ac3155ca3bbabbf75a8
  Platform:
    osname=cygwin, osvers=1.7.9(0.23753), archname=cygwin-thread-multi-64int
    uname='cygwin_nt-6.1-wow64 katipo 1.7.9(0.23753) 2011-03-29 10:10 i686 cygwin '
    config_args='-de -Dprefix=/home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29 -Dusedevel'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=y, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -fno-strict-aliasing -pipe -fstack-protector',
    optimize='-O3',
    cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -fno-strict-aliasing -pipe -fstack-protector'
    ccversion='', gccversion='4.5.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='g++', ldflags =' -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /lib
    libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat
    perllibs=-ldl -lcrypt
    libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=cygperl5_15_6.dll
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' --shared  -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -L/usr/local/lib -fstack-protector'


Characteristics of this binary (from libperl):
  Compile-time options: HAS_TIMES MULTIPLICITY MYMALLOC PERLIO_LAYERS
                        PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT
                        PERL_MALLOC_WRAP PERL_PRESERVE_IVUV PERL_USE_DEVEL
                        PERL_USE_SAFE_PUTENV USE_64_BIT_INT USE_ITHREADS
                        USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE
                        USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO
                        USE_PERL_ATOF USE_REENTRANT_API
  Built under cygwin
  Compiled at Jan  2 2012 11:43:57
  %ENV:
    PERLBREW_BASHRC_VERSION="0.33"
    PERLBREW_HOME="/home/Kent/.perlbrew"
    PERLBREW_PATH="/home/Kent/perl5/perlbrew/bin:/home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/bin"
    PERLBREW_PERL="blead-2012-01-02-11-29"
    PERLBREW_ROOT="/home/Kent/perl5/perlbrew"
    PERLBREW_VERSION="0.33"
  @INC:
    /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6/cygwin-thread-multi-64int
    /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/site_perl/5.15.6
    /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/5.15.6/cygwin-thread-multi-64int
    /home/Kent/perl5/perlbrew/perls/blead-2012-01-02-11-29/lib/5.15.6
    .

 

Subject: cygwin_newline.t
#!/usr/bin/env perl use strict; use warnings; use Test::More; use Test::Fatal; use Carp::Always; use File::Spec::Functions qw( updir catdir rel2abs canonpath curdir ); use Cwd (); my $cwd = Cwd::abs_path; my $subdir = 'test' . $$ . "\n" . 'newline'; my $abs_subdir; is exception { $abs_subdir = catdir( $cwd , $subdir ); }, undef, 'Can concat dirs with \n'; is exception { ( mkdir $abs_subdir ) or fail 'Cannot mkdir with \n'; }, undef, 'mkdir is nonfatal with \n'; is exception { ( chdir $abs_subdir ) or fail 'Cannot chdir to \n'; }, undef, 'chdir is nonfatal with \n'; is exception { note "Cwd::abs_path = " . Cwd::abs_path; }, undef , 'abs_path doesn\'t fatal on \n'; is exception { note "Cwd::_perl_abs_path = " . Cwd::_perl_abs_path; }, undef , '_perl_abs_path doesn\'t fatal on \n'; is exception { note "updir is: " . updir; }, undef, 'updir doesn\'t fatal on \n'; is exception { note "curdir is: " . curdir; }, undef, 'curdir doesn\'t fatal on \n'; is exception { note "updir is: " . canonpath(rel2abs( updir )); }, undef, 'rel2abs updir doesn\'t fatal on \n'; is exception { note "curdir is: " . canonpath(rel2abs( curdir )); }, undef, 'rel2abs curdir doesn\'t fatal on \n'; chdir $cwd; done_testing;