go: path/filepath: EvalSymlinks fails when target is file
What version of Go are you using (go version)?
go version devel +d459962967 Fri Dec 28 22:14:11 2018 +0000 windows/amd64
Does this issue reproduce with the latest release?
No. This bug is not present in go1.11.
What operating system and processor architecture are you using (go env)?
go env Output
set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\Alex\AppData\Local\go-build set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=c:\users\alex\dev set GOPROXY= set GORACE= set GOROOT=c:\users\alex\dev\go set GOTMPDIR= set GOTOOLDIR=c:\users\alex\dev\go\pkg\tool\windows_amd64 set GCCGO=gccgo set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD= 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 set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Alex\AppData\Local\Temp\go-build894807034=/tmp/go-build -gno-record-gcc-switches
What did you do?
I run this test
package main_test
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
func TestNTNamespaceSymlink(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "TestNTNamespaceSymlink")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
tmpfile := filepath.Join(tmpdir, "file")
err = ioutil.WriteFile(tmpfile, []byte(""), 0666)
if err != nil {
t.Fatal(err)
}
vol := filepath.VolumeName(tmpdir)
output, err := exec.Command("cmd", "/c", "mountvol", vol, "/L").CombinedOutput()
if err != nil {
t.Fatalf("failed to run mountvol %v /L: %v %q", vol, err, output)
}
target := strings.Trim(string(output), " \n\r")
target = target + tmpfile[3:]
link := filepath.Join(tmpdir, "link")
output, err = exec.Command("cmd", "/c", "mklink", link, target).CombinedOutput()
if err != nil {
t.Fatalf("failed to run mklink %v %v: %v %q", link, target, err, output)
}
got, err := filepath.EvalSymlinks(link)
if err != nil {
t.Fatal(err)
}
if want := tmpfile; got != want {
t.Errorf(`EvalSymlinks(%q): got %q, want %q`, link, got, want)
}
}
What did you expect to see?
I expect the test to PASS.
What did you see instead?
=== RUN TestNTNamespaceSymlink
--- FAIL: TestNTNamespaceSymlink (0.08s)
a_test.go:41: The system cannot find the path specified.
FAIL
I can make the test pass, if I use commit before b32ee0a3c004d4ef79d92bd63200008456da50f3.
/cc @Gnouc and @ianlancetaylor
Alex
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 20 (18 by maintainers)
Not quite the same. walkSymlinks returns error
https://go-review.googlesource.com/c/go/+/156398/1/src/path/filepath/symlink.go
on lines 76, 81, 90 and 95. My CL only skips evalSymlinksUsingGetFinalPathNameByHandle when error is returned via line 81 (when we find non-symlink/non-directory, but more path to parse on the right remains). And your CL skips evalSymlinksUsingGetFinalPathNameByHandle also when lines 76 and 95 are hit. Line 76 returns error from os.Lstat. What happens, if that os.Lstat. returns syscall.ENOTDIR? Why should we skip evalSymlinksUsingGetFinalPathNameByHandle , if os.Lstat. returns syscall.ENOTDIR? Same for line 95.
See my description above. Also I would like future code reader (myself) to see, that something special is happening here. I can do this by adding comments in many places. But using unusual name also feels good to me.
I want it look weird. Otherwise I will miss tricky logic in this code. If you have better name for slashAfterFilePathError, I am listening.
Alex