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

-e tests not reliable under Win32 #7410

Open
p5pRT opened this issue Jul 7, 2004 · 9 comments
Open

-e tests not reliable under Win32 #7410

p5pRT opened this issue Jul 7, 2004 · 9 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Jul 7, 2004

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

Searchable as RT30622$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 7, 2004

From @demerphq

Created by @demerphq

The following script produces incorrect results on Win32, Cygwin build or
ActiveState builds. This occurs under all 5.8.x as well as 5.6.x, and
possibly earlier.

Original report raised in Perlmonks:
http://perlmonks.org/index.pl?node_id=371904
Some trace analysis of the cause is present there FWIW.

use strict;
use warnings;

my @files = (' ', ' . . ', ' .. ', ' ', ' . ');

foreach (@files) {
print "[$_] - ", -e $_ ? "yes\n" : "no\n";
}

Produces on the two different versions i have handy:

C:\Temp>perl test_file_exists.pl
[ ] - yes
[ . . ] - yes
[ .. ] - yes
[ ] - yes
[ . ] - yes

This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2001, Larry Wall

Binary build 633 provided by ActiveState Corp. http://www.ActiveState.com
Built 21:33:05 Jun 17 2002
C:\Temp>perl5.8.0 test_file_exists.pl
[ ] - yes
[ . . ] - yes
[ .. ] - yes
[ ] - yes
[ . ] - yes

This is perl, v5.8.0 built for cygwin-multi-64int

Copyright 1987-2002, Larry Wall
Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.6.1:

Configured by ActiveState at Mon Jun 17 21:32:50 2002.

Summary of my perl5 (revision 5 version 6 subversion 1) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cl', ccflags ='-nologo -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE
-DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DPERL_MSVCRT_READFIX',
    optimize='-O1 -MD -DNDEBUG',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release
-libpath:"E:\Perl\lib\CORE"  -machine:x86'
    libpth="E:\DotNet\FrameworkSDK\Lib\" "E:\Perl\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib
uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib
uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release
-libpath:"E:\Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY


@INC for perl v5.6.1:
    D:\development\perl\devlib
    E:/Perl/lib
    E:/Perl/site/lib
    .


Environment for perl v5.6.1:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=*PRIVATE*
    PERL5LIB=D:\development\perl\devlib
    PERL5_CPANPLUS_CONFIG=e:\.cpanplus\config
    PERL_BADLANG (unset)
    SHELL (unset)

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jun 5, 2008

From @smpeters

It appears that this is OK on Cygwin now, although not on Windows.

$ perl rt_30622.pl
[ ] - no
[ . . ] - no
[ .. ] - no
[ ] - no
[ . ] - no
$ perl -v

This is perl, v5.8.8 built for cygwin-thread-multi-64int

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jun 5, 2008

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

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 7, 2016

From @dcollinsn

This bug does still exist under ActiveState perl 5.24.0 x64.

Is this "correct" as a quirk of Windows, or is perl actually doing something wrong?

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Dec 17, 2017

From zefram@fysh.org

This looks like it's a platform quirk in filename resolution, not
a Perl bug. It's similar to #14687 which is concerned with
"..." as a filename. Can someone with Windows please check​: are you
able to open() these filenames that pass -e?

-zefram

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Dec 17, 2017

From @eserte

Dana Sat, 16 Dec 2017 17​:06​:59 -0800, zefram@​fysh.org reče​:

This looks like it's a platform quirk in filename resolution, not
a Perl bug. It's similar to [perl #124443] which is concerned with
"..." as a filename. Can someone with Windows please check​: are you
able to open() these filenames that pass -e?

open fails with "No such file or directory" (Win7, Strawberry Perl 5.26.0.x)

Regards,
  Slaven

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Dec 17, 2017

From zefram@fysh.org

slaven@​rezic.de via RT wrote​:

open fails with "No such file or directory" (Win7, Strawberry Perl 5.26.0.x)

Well, that's interesting. This needs the attention of a platform expert.
-e ought to accurately reflect what can be open()ed.

-zefram

@toddr
Copy link
Member

@toddr toddr commented Feb 13, 2020

This is also reminiscent of #12431

genio added a commit to genio/perl5 that referenced this issue Oct 15, 2020
As discussed on the mailing list here:
https://www.nntp.perl.org/group/perl.perl5.porters/2020/10/msg258453.html

This just removes the declaration that we support the very old versions
of Windows that have long since been EOLed.

For reference of problems related to maintaining the EOLed versions:
Perl#4145
Perl#6080
Perl#7410
Perl#8502
Perl#9025
Perl#12431
Perl#14687
@tonycoz
Copy link
Contributor

@tonycoz tonycoz commented Dec 2, 2020

This still occurs in 5.33 blead, and the version of windows doesn't appear to be relevant.

This appears to be a windows specific behaviour, I commented out the PerlDir_mapA() call from Win32 stat and the call to CreateFileA() in the new version of stat (and done by newer versions of Microsoft's UCRT) successfully opened a name of " . . ".

win32_opendir() uses the FindFirstFileW() function which unlike POSIX opendir wants a glob()-like pattern, so win32_opendir(), seeing no trailing / adds that and the globby "*", so for my " . . " it ends up with " . . /*" which FileFirstFileW() fails on, producing a ERROR_PATH_NOT_FOUND error.

I expect we could prevent that difference by using the FileFullDirectoryInfo and FileFullDirectoryRestartInfo FileInformationClass for GetFileInformationByHandleEx(), but this API requires Vista or later,

Note that this would make stat() and opendir() consistently both successfully open " . . " and similar names, not prevent it.

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

Successfully merging a pull request may close this issue.

None yet
3 participants