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

Comments

@AudriusButkevicius
Copy link
Contributor

@AudriusButkevicius 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

This comment has been minimized.

Copy link
Member

@mvdan mvdan commented Aug 25, 2018

Does this only happen on Windows?

@AudriusButkevicius

This comment has been minimized.

Copy link
Contributor Author

@AudriusButkevicius AudriusButkevicius commented Aug 25, 2018

Yes, as far as I found.

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Aug 25, 2018

@alexbrainman

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman commented Sep 2, 2018

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

Alex

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Sep 8, 2018

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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Oct 20, 2018

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

@alexbrainman

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman commented Oct 20, 2018

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

Does it fixes your problem?

Thank you.

Alex

@AudriusButkevicius

This comment has been minimized.

Copy link
Contributor Author

@AudriusButkevicius AudriusButkevicius commented Oct 20, 2018

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

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman commented Oct 20, 2018

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

@gopherbot gopherbot closed this in f108158 Nov 2, 2018
@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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.