From 44cf595a7efcd3d7048c745d1d1531696bcb5941 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sat, 5 Jan 2019 18:35:27 +1100 Subject: path/filepath: return special error from EvalSymlinks CL 155597 attempted to fix #29372. But it failed to make all new test cases pass. Also CL 155597 broke some existing code (see #29449 for details). Make small adjustment to CL 155597 that fixes both #29372 and #29449. Suggested by Ian. Updates #29372 Fixes #29449 Change-Id: I9777a615514d3f152af5acb65fb1239e696607b6 Reviewed-on: https://go-review.googlesource.com/c/156398 Run-TryBot: Alex Brainman Reviewed-by: Ian Lance Taylor --- src/path/filepath/path_windows_test.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'src/path/filepath/path_windows_test.go') diff --git a/src/path/filepath/path_windows_test.go b/src/path/filepath/path_windows_test.go index 63eab18116..3fcccfab78 100644 --- a/src/path/filepath/path_windows_test.go +++ b/src/path/filepath/path_windows_test.go @@ -536,17 +536,39 @@ func TestNTNamespaceSymlink(t *testing.T) { } target := strings.Trim(string(output), " \n\r") - link := filepath.Join(tmpdir, "link") - output, err = exec.Command("cmd", "/c", "mklink", "/J", link, target).CombinedOutput() + dirlink := filepath.Join(tmpdir, "dirlink") + output, err = exec.Command("cmd", "/c", "mklink", "/J", dirlink, target).CombinedOutput() if err != nil { - t.Fatalf("failed to run mklink %v %v: %v %q", link, target, err, output) + t.Fatalf("failed to run mklink %v %v: %v %q", dirlink, target, err, output) } - got, err := filepath.EvalSymlinks(link) + got, err := filepath.EvalSymlinks(dirlink) if err != nil { t.Fatal(err) } if want := vol + `\`; got != want { - t.Errorf(`EvalSymlinks(%q): got %q, want %q`, link, got, want) + t.Errorf(`EvalSymlinks(%q): got %q, want %q`, dirlink, got, want) + } + + file := filepath.Join(tmpdir, "file") + err = ioutil.WriteFile(file, []byte(""), 0666) + if err != nil { + t.Fatal(err) + } + + target += file[len(filepath.VolumeName(file)):] + + filelink := filepath.Join(tmpdir, "filelink") + output, err = exec.Command("cmd", "/c", "mklink", filelink, target).CombinedOutput() + if err != nil { + t.Fatalf("failed to run mklink %v %v: %v %q", filelink, target, err, output) + } + + got, err = filepath.EvalSymlinks(filelink) + if err != nil { + t.Fatal(err) + } + if want := file; got != want { + t.Errorf(`EvalSymlinks(%q): got %q, want %q`, filelink, got, want) } } -- cgit v1.3