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

os: Stat on a symlink fails when path has a trailing slash #27225

Closed
AudriusButkevicius opened this issue Aug 25, 2018 · 9 comments
Closed

os: Stat on a symlink fails when path has a trailing slash #27225

AudriusButkevicius opened this issue Aug 25, 2018 · 9 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows

Comments

@AudriusButkevicius
Copy link
Contributor

AudriusButkevicius commented Aug 25, 2018

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

go version go1.11 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

Windows 10 with Developer mode enabled (allowing to create symlinks for unprivileged users)

What did you do?

c:\temp>type test.go
package main

import (
  "os"
  "fmt"
)

func main() {
  fmt.Println(os.Lstat(`c:\temp\b`))
  fmt.Println(os.Lstat(`c:\temp\b\`))
}
c:\temp>mkdir a

c:\temp>mklink /D b a
symbolic link created for b <<===>> a

c:\temp>cmd /c "set GOROOT=c:\go1.10.4&& c:\go1.10.4\bin\go.exe run test.go"
&{b {1040 {477620318 30686378} {477620318 30686378} {477620318 30686378} 0 0} 0 {0 0} c:\temp\b 0 0 0 false} <nil>
&{b {1040 {477620318 30686378} {477620318 30686378} {477620318 30686378} 0 0} 0 {0 0} c:\temp\b\ 0 0 0 false} <nil>

c:\temp>cmd /c "set GOROOT=c:\go&& c:\go\bin\go.exe run test.go"
&{b 1040 {477620318 30686378} {477620318 30686378} {477620318 30686378} 0 0 2684354572 0 {0 0} c:\temp\b 0 0 0 false} <nil>
<nil> FindFirstFile c:\temp\b\: The system cannot find the file specified.

Same issue between Stat and Lstat

What did you expect to see?

Stat to succeed, like it did in Go 1.10.4

What did you see instead?

Stat failed

@mvdan
Copy link
Member

mvdan commented Aug 25, 2018

Does this only happen on Windows?

@AudriusButkevicius
Copy link
Contributor Author

Yes, as far as I found.

@bradfitz bradfitz added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 25, 2018
@bradfitz
Copy link
Contributor

/cc @alexbrainman

@alexbrainman
Copy link
Member

@AudriusButkevicius thank you for reporting the issue. I will investigate when I have time.

Alex

@gopherbot
Copy link

Change https://golang.org/cl/134195 mentions this issue: os: use FILE_FLAG_OPEN_REPARSE_POINT in SameFile

gopherbot pushed a commit that referenced this issue Sep 29, 2018
SameFile opens file to discover identifier and volume serial
number that uniquely identify the file. SameFile uses Windows
CreateFile API to open the file, and that works well for files
and directories. But CreateFile always follows symlinks, so
SameFile always opens symlink target instead of symlink itself.

This CL uses FILE_FLAG_OPEN_REPARSE_POINT flag to adjust
CreateFile behavior when handling symlinks.

As per https://docs.microsoft.com/en-us/windows/desktop/FileIO/symbolic-link-effects-on-file-systems-functions#createfile-and-createfiletransacted

"... If FILE_FLAG_OPEN_REPARSE_POINT is specified and:

If an existing file is opened and it is a symbolic link, the handle
returned is a handle to the symbolic link. ...".

I also added new tests for both issue #21854 and #27225.
Issue #27225 is still to be fixed, so skipping the test on
windows for the moment.

Fixes #21854
Updates #27225

Change-Id: I8aaa13ad66ce3b4074991bb50994d2aeeeaa7c95
Reviewed-on: https://go-review.googlesource.com/134195
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/143578 mentions this issue: os: use CreateFile for Stat of symlinks

@alexbrainman
Copy link
Member

@AudriusButkevicius please try https://go-review.googlesource.com/c/go/+/143578

Does it fixes your problem?

Thank you.

Alex

@AudriusButkevicius
Copy link
Contributor Author

I won't be able to try it out as I have no pc access for 3-4 weeks. Ping @calmh, @imsodin who might be able to help.

@alexbrainman
Copy link
Member

I won't be able to try it out as I have no pc access for 3-4 weeks.

Never mind that. You will try when you can.

Alex

@golang golang locked and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants