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

Windows: Absolute path in target of symlink directory, problem with -e and -d file tests #20533

Closed
hakonhagland opened this issue Nov 21, 2022 · 3 comments · Fixed by #20539
Closed

Comments

@hakonhagland
Copy link
Contributor

hakonhagland commented Nov 21, 2022

I have built a debug version of perl 5.37.6 on Windows 11 using MinGW-w64 and gcc 11.3.0 from https://winlibs.com/ (using the MSVCRT runtime library). Note that this includes #20271, which fixes the readlink behavior on Windows, see #20460 for more information.

When trying to install Path::Tiny using this perl I get a test failure due to -d operator not working on a symlink directory (note: this is a directory, not a file as in #20506). Here is a minimal example:

use feature qw(say);
use strict;
use warnings;
use Cwd qw(getcwd);

my $abspath = getcwd; ## or choose any existing absolute path to a directory here
my $symlink_dir = "A";
my $target = $abspath;
if (!-e $symlink_dir) {
    symlink $target, $symlink_dir or die "Could not create symlink $symlink_dir: $!";
    say "Created symlink dir $symlink_dir with target $target";
}
else {
    die "$symlink_dir already exists..(please delete it first)";
}
if (-d $symlink_dir) {
    say "-d $symlink_dir works";
}
else {
    say "-d $symlink_dir does not work";
}
if (-l $symlink_dir) {
    say "-l $symlink_dir works";
}
else {
    say "-l $symlink_dir does not work";
}

The output is:

-d A does not work
-l A works

Expected output:

-d A works
-l A works

The same problem occurs for the -e operator. If the symlink target is a relative path (not absolute) both -e and -d works fine.

Perl configuration

> perl -V
Summary of my perl5 (revision 5 version 37 subversion 6) configuration:
  Commit id: a589f4b93cf3864d7f665d0974e2d36f028b00b6
  Platform:
    osname=MSWin32
    osvers=10.0.22000.1098
    archname=MSWin32-x64-multi-thread
    uname=''
    config_args='undef'
    hint=recommended
    useposix=true
    d_sigaction=undef
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='gcc'
    ccflags =' -DWIN32 -DWIN64 -DDEBUGGING -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICITY -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D__USE_MINGW_ANSI_STDIO -fwrapv -fno-strict-aliasing -mms-bitfields'
    optimize='-g -O0'
    cppflags='-DWIN32'
    ccversion=''
    gccversion='11.3.0'
    gccosandvers=''
    intsize=4
    longsize=4
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='long long'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='g++'
    ldflags ='-g -L"c:\perl-debug\lib\CORE" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\x86_64-w64-mingw32\lib" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib\gcc\x86_64-w64-mingw32\11.3.0"'
    libpth=C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib C:\Winlibs64-Gcc11.3-msvcrt\mingw64\x86_64-w64-mingw32\lib C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib\gcc\x86_64-w64-mingw32\11.3.0
    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=libperl537.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs
    dlext=dll
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags='-shared -g -L"c:\perl-debug\lib\CORE" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\x86_64-w64-mingw32\lib" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib\gcc\x86_64-w64-mingw32\11.3.0"'


Characteristics of this binary (from libperl):
  Compile-time options:
    DEBUGGING
    HAS_TIMES
    HAVE_INTERP_INTERN
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_HASH_FUNC_SIPHASH13
    PERL_HASH_USE_SBOX32
    PERL_IMPLICIT_SYS
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_TRACK_MEMPOOL
    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_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under MSWin32
  Compiled at Nov  2 2022 00:00:55
  @INC:
    C:/perl-debug/site/lib
    C:/perl-debug/lib
@hakonhagland
Copy link
Contributor Author

hakonhagland commented Nov 22, 2022

-d A does not work

Seems like CreateFileA() returns INVALID_HANDLE at line 1812 in win32.c for any absolute path if path is a symlink directory. It does not matter if path uses forward or backward slashes. The result is that execution continues to line 1822, and S_follow_symlinks_to() which is called at this line, is able to read the target of the symlink dir for the first call to win32_readlink() at line 1715, but the while loop (line 1715) continues and tries to read the target as a symlink (but the target of the original symlink is not a symlink itself), and then the second call to win32_readlink() fails, and execution continues to line 1776 and CreateFileA() fails to open the target as a reparse point (since the target is not a reparse point) and execution continues to line 1794 which sets errno to EINVAL, and then INVALID_HANDLE is returned at line 1797 and then -1 is returned at line 1825.

@tonycoz
Copy link
Contributor

tonycoz commented Nov 23, 2022

It looks like the wrong type of symlink is being created.

@hakonhagland
Copy link
Contributor Author

It looks like the wrong type of symlink is being created.

@tonycoz Yes that could be the problem! Let me know if I should do any more testing

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

Successfully merging a pull request may close this issue.

3 participants