-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: FileInfo Mode on Windows incorrectly interpreting WSL symlinks (reparse points) as regular files always #42184
Comments
Thank you for filing this issue @kfsone and welcome to the Go project! Interesting bug, and thank you for the background. Please feel free to send a change to fix this as per https://golang.org/doc/contribute.html or even just a PR on Github after signing the CLA, it would be Just for full disclosure we are about 6 days away from a code freeze for Go1.16, thus if you can, please send a change, |
CreateFile fail to open symlink created on WSL2 without diff --git a/src/os/stat_windows.go b/src/os/stat_windows.go
index da4c49090e..43f176376c 100644
--- a/src/os/stat_windows.go
+++ b/src/os/stat_windows.go
@@ -103,7 +103,7 @@ func stat(funcname, name string, createFileAttrs uint32) (FileInfo, error) {
// statNolog implements Stat for Windows.
func statNolog(name string) (FileInfo, error) {
- return stat("Stat", name, syscall.FILE_FLAG_BACKUP_SEMANTICS)
+ return stat("Stat", name, syscall.FILE_FLAG_OPEN_REPARSE_POINT|syscall.FILE_FLAG_BACKUP_SEMANTICS)
}
// lstatNolog implements Lstat for Windows. |
Hmm, TestDirectoryJunction fail if adding |
Change https://golang.org/cl/265037 mentions this issue: |
Note the distinction between |
Notes from looking at implementing handling for this:
> cd $env:TEMP ; rm -recurs -force symlinks ; cd (mkdir symlinks)
[C:\Users\oliver\AppData\Local\Temp\symlinks]
> wsl ln -s target.txt relative.lnk
[C:\Users\oliver\AppData\Local\Temp\symlinks]
> echo this is target >target.txt
[C:\Users\oliver\AppData\Local\Temp\symlinks]
> get-content target.txt
this
is
target
[C:\Users\oliver\AppData\Local\Temp\symlinks]
> get-content relative.lnk
Get-Content: The file cannot be accessed by the system. : 'C:\Users\oliver\AppData\Local\Temp\symlinks\relative.lnk'
[C:\Users\oliver\AppData\Local\Temp\symlinks]
> wsl cat relative.lnk
this
is
target
[C:\Users\oliver\AppData\Local\Temp\symlinks]
> fsutil reparsePoint query relative.lnk
Reparse Tag Value : 0xa000001d
Tag value: Microsoft
Tag value: Name Surrogate
Reparse Data Length: 0xe
Reparse Data:
0000: 02 00 00 00 74 61 72 67 65 74 2e 74 78 74 ....target.txt
Perhaps for now, rather than appearing as a symlink, these entities should at least appear as not being regular files? |
@odeke-em Taking a look; previously signed the CLA for grpc in 2014, setup a password. The windows tests appear to be failing tho as a result of #40604 but I also experience a seemingly obvious failure of TestLookPath:
|
We were previously using an incorrect (or at least not completely correct) symbolic link detection mechanism that differed from that of the Go standard library. On Windows, where we use the os package to drive some of our filesystem implementation, this led to spurious symbolic link reports. This commit unifies Mutagen's symbolic link definition with that of the Go standard library. Note that the Go standard library still has an open issue regarding symbolic link classification with WSL symbolic links (golang/go#42184), so we inherit that for now, but we should be able to adjust our definition once that issue is resolved. Fixes #248. Signed-off-by: Jacob Howard <jacob@havoc.io>
Change https://go.dev/cl/516555 mentions this issue: |
I don't think we should special-case WSL symlinks (aka Also, WSL symlinks can't be opened from Windows, only from within WSL, so if we identify them as |
Previously, os.Stat only followed IO_REPARSE_TAG_SYMLINK and IO_REPARSE_TAG_MOUNT_POINT reparse points. This CL generalize the logic to detect which reparse points to follow by using the reparse tag value to determine whether the reparse point refers to another named entity, as documented in https://learn.microsoft.com/en-us/windows/win32/fileio/reparse-point-tags. The new behavior adds implicit support for correctly stat-ing reparse points other than mount points and symlinks, e.g., IO_REPARSE_TAG_WCI_LINK and IO_REPARSE_TAG_IIS_CACHE. Updates #42184 Change-Id: I51f56127d4dc6c0f43eb5dfa3bfa6d9e3922d000 Reviewed-on: https://go-review.googlesource.com/c/go/+/516555 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Called
os.FileInfo.Mode.IsRegular
and got the wrong result.This is caused by a WSL symlink:
Running the following go code:
produces:
Windows is definitely telling us it's a reparse point:
FileAttributes: 0x420
includes the 1024 required. The issue here is the value ofReserved0
, which is not being tested for:According to https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/c8e77b37-3909-4fe6-a4ea-2b9d423b1ee4
This appears it would require a change to src/os/types_windows.go lines 104,105.
The text was updated successfully, but these errors were encountered: