Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abs_path dies on Windows when called with non-existent path #12693

Open
p5pRT opened this issue Jan 8, 2013 · 12 comments
Open

abs_path dies on Windows when called with non-existent path #12693

p5pRT opened this issue Jan 8, 2013 · 12 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 8, 2013

Migrated from rt.perl.org#116332 (status was 'open')

Searchable as RT116332$

@p5pRT
Copy link
Author

p5pRT commented Jan 8, 2013

From @stsc

Created by @stsc

#!perl

use strict;
use warnings;

use Cwd qw(abs_path);
use File​::Spec;

$| = 1;

print "rel2abs​:\t";
print File​::Spec->rel2abs('not_exists'), "\n";

print "abs_path​:\t";
print abs_path('not_exists'), "\n";

__OUTPUT__
[sts@​kronos ~]$ perl path.pl
rel2abs​: /home/sts/not_exists
abs_path​: /home/sts/not_exists

C​:\>perl path.pl
rel2abs​: C​:\not_exists
abs_path​: not_exists​: No such file or directory at path.pl line 15

According to fail reports from CPAN testers for Hook-Output-File-0.07,
different Cwd versions are affected (3.30, 3.31, 3.33 and 3.39_02, at
least). Noteworthy, fails on Cygwin too.

Perl Info

Flags:
    category=library
    severity=medium
    module=Cwd

Site configuration information for perl 5.12.1:

Configured by 1 at Thu Jul 29 16:39:48 2010.

Summary of my perl5 (revision 5 version 12 subversion 1) configuration:
   
  Platform:
    osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
    uname='Win32 strawberryperl 5.12.1.0 #1 Thu Jul 29 10:08:11 2010 i386'
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT  -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields -DPERL_MSVCRT_READFIX',
    optimize='-s -O2',
    cppflags='-DWIN32'
    ccversion='', gccversion='4.4.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='g++', ldflags ='-s -L"C:\Programme\Strawberry_Perl\perl\lib\CORE" -L"C:\Programme\Strawberry_Perl\c\lib"'
    libpth=C:\Programme\Strawberry_Perl\c\lib C:\Programme\Strawberry_Perl\c\i686-w64-mingw32\lib
    libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    libc=, so=dll, useshrplib=true, libperl=libperl512.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-mdll -s -L"C:\Programme\Strawberry_Perl\perl\lib\CORE" -L"C:\Programme\Strawberry_Perl\c\lib"'

Locally applied patches:
    


@INC for perl 5.12.1:
    C:/Programme/Strawberry_Perl/perl/site/lib
    C:/Programme/Strawberry_Perl/perl/vendor/lib
    C:/Programme/Strawberry_Perl/perl/lib
    .


Environment for perl 5.12.1:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Programme\Strawberry_Perl\c\bin;C:\Programme\Strawberry_Perl\perl\site\bin;C:\Programme\Strawberry_Perl\perl\bin;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\MinGW\bin
    PERL_BADLANG (unset)
    SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2017

From @jkeenan

On Tue, 08 Jan 2013 00​:08​:06 GMT, stsc@​refcnt.org wrote​:

This is a bug report for perl from stsc@​refcnt.org,
generated with the help of perlbug 1.39 running under perl 5.12.1.

-----------------------------------------------------------------
[Please describe your issue here]

#!perl

use strict;
use warnings;

use Cwd qw(abs_path);
use File​::Spec;

$| = 1;

print "rel2abs​:\t";
print File​::Spec->rel2abs('not_exists'), "\n";

print "abs_path​:\t";
print abs_path('not_exists'), "\n";

__OUTPUT__
[sts@​kronos ~]$ perl path.pl
rel2abs​: /home/sts/not_exists
abs_path​: /home/sts/not_exists

C​:\>perl path.pl
rel2abs​: C​:\not_exists
abs_path​: not_exists​: No such file or directory at path.pl line
15

According to fail reports from CPAN testers for Hook-Output-File-0.07,
different Cwd versions are affected (3.30, 3.31, 3.33 and 3.39_02, at
least). Noteworthy, fails on Cygwin too.

Since this ticket has not garnered a response in four years, I am attaching the OP's test program for better viewability.

When I ran it on Linux, I got the same output as the OP​:

#####
$ pwd
/tmp

$ perl 116332-path.pl
rel2abs​: /tmp/not_exists
abs_path​: /tmp/not_exists
#####

Could we get this run on various flavors of Windows?

Thank you very much.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=library
severity=medium
module=Cwd
---
Site configuration information for perl 5.12.1​:

Configured by 1 at Thu Jul 29 16​:39​:48 2010.

Summary of my perl5 (revision 5 version 12 subversion 1)
configuration​:

Platform​:
osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
uname='Win32 strawberryperl 5.12.1.0 #1 Thu Jul 29 10​:08​:11 2010
i386'
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT
-DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-
strict-aliasing -mms-bitfields -DPERL_MSVCRT_READFIX',
optimize='-s -O2',
cppflags='-DWIN32'
ccversion='', gccversion='4.4.3', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long
long', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='g++', ldflags ='-s
-L"C​:\Programme\Strawberry_Perl\perl\lib\CORE"
-L"C​:\Programme\Strawberry_Perl\c\lib"'
libpth=C​:\Programme\Strawberry_Perl\c\lib
C​:\Programme\Strawberry_Perl\c\i686-w64-mingw32\lib
libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32
-lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool
-lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid
-lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
libc=, so=dll, useshrplib=true, libperl=libperl512.a
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -s
-L"C​:\Programme\Strawberry_Perl\perl\lib\CORE"
-L"C​:\Programme\Strawberry_Perl\c\lib"'

Locally applied patches​:

---
@​INC for perl 5.12.1​:
C​:/Programme/Strawberry_Perl/perl/site/lib
C​:/Programme/Strawberry_Perl/perl/vendor/lib
C​:/Programme/Strawberry_Perl/perl/lib
.

---
Environment for perl 5.12.1​:
HOME (unset)
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=C​:\WINDOWS\system32;C​:\WINDOWS;C​:\WINDOWS\System32\Wbem;C​:\Programme\Strawberry_Perl\c\bin;C​:\Programme\Strawberry_Perl\perl\site\bin;C​:\Programme\Strawberry_Perl\perl\bin;C​:\WINDOWS\system32\WindowsPowerShell\v1.0;C​:\MinGW\bin
PERL_BADLANG (unset)
SHELL (unset)

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2017

From @jkeenan

116332-path.pl

#!perl

use strict;
use warnings;

use Cwd qw(abs_path);
use File::Spec;

$| = 1;

print "rel2abs:\t";
print File::Spec->rel2abs('not_exists'), "\n";

print "abs_path:\t";
print abs_path('not_exists'), "\n";

@p5pRT
Copy link
Author

p5pRT commented Feb 17, 2017

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Feb 18, 2017

From itcharlie@gmail.com

Path doesn't display on Windows 10 Strawberry Perl 5.24.1

Powershell Output​:

PS C​:\Users\cgonzalez\Desktop> perl .\path.pl
rel2abs​: C​:\Users\cgonzalez\Desktop\not_exists
abs_path​: not_exists​: No such file or directory at .\path.pl line 15.
PS C​:\Users\cgonzalez\Desktop>

FYI I also tried Command Prompt DOS and it was the same output.

@p5pRT

This comment has been minimized.

@p5pRT
Copy link
Author

p5pRT commented Feb 18, 2017

From nanis@cpan.org

As I discussed here[1], this happens because of the pure Perl version
croaks whereas the XS version used in *nix systems doesn't.

For Dancer, I recommended using File​::Spec->rel2abs[2].

[1]​: https://www.nu42.com/2010/05/why-cant-i-get-dancers-version-from.html
[2]​: PerlDancer/Dancer#75

@toddr
Copy link
Member

toddr commented Feb 13, 2020

So can we just alter Cwd.pm to use File::Spec on windows?

@Grinnz
Copy link
Contributor

Grinnz commented Feb 13, 2020

No, rel2abs is a different operation, it does not consult the filesystem.

@richardleach
Copy link
Contributor

FWIW, Win 10, Strawb 5.30 - different error from abs_path:

C:\Strawberry>perl path.pl
rel2abs:        C:\Strawberry\not_exists
abs_path:       Use of uninitialized value in print at path.pl line 15.

@richardleach
Copy link
Contributor

On Windows, abs_path maps to fast_abs_path in Cwd.pm.

Looks like commit a97021b (shipped in 5.28) changed this function from croaking to returning undef.

@richardleach
Copy link
Contributor

richardleach commented Feb 14, 2020

On Linux, abs_path uses bsd_realpath in Cwd.xs, which is documented to:

 * Find the real name of path, by removing all ".", ".." and symlink
 * components.  Returns (resolved) on success, or (NULL) on failure,
 * in which case the path which caused trouble is left in (resolved).

Technically, the problem in this ticket - abs_path dies on Windows - has been fixed.

But the behaviour of abs_path still differs between platforms. Should the behaviours be made consistent and if so, which way around?

PS Other platform variants:

  • dos, cygwin, amigaos all use the same fast_abs_path as MSWin32
  • qnx uses _qnx_abs_path which still dies if passed an non-existent path
  • vms uses _vms_abs_path in which it does....well, stuff. Looks like 4-5 different cases, some of which seem like they may not be fatal but one definitely is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants