8000 os: Stat on symlink fails on windows · Issue #19922 · golang/go · GitHub
[go: up one dir, main page]

Skip to content
os: Stat on symlink fails on windows #19922
Closed
@alexbrainman

Description

@alexbrainman

What version of Go are you using (go version)?

go version devel +423e7e6 Mon Apr 10 20:57:08 2017 +0000 windows/amd64

What operating system and processor architecture are you using (go env)?

Windows 7

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=c:\dev
set GORACE=
set GOROOT=C:\dev\go
set GOTOOLDIR=C:\dev\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\brainman\AppData\Local\Temp\go-build979456703=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

What did you do?

You will need 2 computers to reproduce this issue.

On computer 1 run these commands:

mkdir C:\alex\localdir
mkdir C:\alex\mountpoint
net share mountpoint=C:\alex\mountpoint
mklink /J C:\alex\mountpoint\junc c:\alex\localdir

On computer 2 run:

net use x: \\computer1\mountpoint

then run this https://play.golang.org/p/5m0ZwZFB3z program.

What did you expect to see?

I expect to see no output.

What did you see instead?

I see:

panic: GetFileAttributesEx c:\alex\localdir: The system cannot find the path specified.

goroutine 1 [running]:
main.main()
        c:/dev/src/t/main.go:10 +0x6a
exit status 2

It appears Go program on computer 2 fallowing link with the target of c:\alex\localdir that only exists on computer 1.

On computer 2:

C:\>dir x:
 Volume in drive X has no label.
 Volume Serial Number is 1234-4321

 Directory of X:\

10/04/2017  12:46 PM    <DIR>          .
10/04/2017  12:46 PM    <DIR>          ..
10/04/2017  12:46 PM    <JUNCTION>     junc [c:\alex\localdir]
               0 File(s)              0 bytes
               3 Dir(s)   952 bytes free

C:\>dir c:\alex\localdir
The system cannot find the file specified.

C:\>

I have discovered this while investigating issue #18555. Original idea comes from nodejs/node#8897 (comment) Perhaps this issue and #18555 are duplicates. But I am creating new issue just in case there is something different to learn from this. Also it is easier to reproduce - you don't need Docker for Windows.

I have no idea what to do here. In issue #18555 and here link targets are paths that do not exist.

Perhaps os.Stat should not follow symlinks on windows. But that will break some programs. It will break our tests.

On the other hand, I was planning to change windows os.FileInfo.Mode() to return either os.ModeSymlink or os.ModeDir instead of their union (see #17540 (comment) ). That should fix issues #10424, #17540 and #17541. Not sure what to do now.

Also there is filepath.EvalSymlinks to consider.

@rsc @ianlancetaylor what do you think?

Thank you.

Alex

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0